gpt4 book ai didi

mysql - 当值不存在于两列中时选择

转载 作者:行者123 更新时间:2023-11-29 01:14:08 25 4
gpt4 key购买 nike

我有两个字段,emailaddlEmail。如果给定的电子邮件地址不在任一字段中,我需要一个仅选择记录的选择。

尝试对两列使用 NOT IN(返回:基数违规:1241 操作数应包含 2 列:)

SELECT WebUsername, 
WebPassword,
Active,
Email,
AddlEmail,
ShowYear
FROM Exhibitors e
WHERE e.Active = '-1'
AND e.ShowYear = 2013
AND (e.Email, e.AddlEmail) NOT IN ('test@test.com', 'test2@test.com')"

我已经尝试过 AND 和 OR,但由于显而易见的原因它们不起作用。

为了尽量彻底:

$emails = "'email@email.com', 'email2@email.com'";
// example table data for 2 fields in question
Row | Email | AddlEmail
1 | email@email.com | email3@email.com
2 | email4@email.com | email2@email.com
3 | email5@email.com | null
4 | email6@email.com | email7@email.com

查询应该只返回第 3 行和第 4 行。

感谢您的浏览,如果您需要进一步说明,请告诉我。

克里斯

编辑:响应已发布答案的示例表:

CREATE TABLE `doubleSelect` (
`Email` varchar(255) DEFAULT NULL,
`AddlEmail` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `doubleSelect` (`Email`, `AddlEmail`) VALUES
('email@email.com', 'email2@email.com'),
('email2@email.com', 'email3@email.com'),
('email4@email.com', 'email5@email.com'),
('email6@email.com', 'email@email.com'),
(NULL, 'email@email.com'),
('email2@email.com', NULL);

示例查询(不返回最后一行,它应该):

SELECT *
FROM `doubleSelect`
WHERE Email NOT
IN (
'email@email.com'
)
AND AddlEmail NOT
IN (
'email@email.com'
)

最佳答案

简单地

AND e.Email NOT IN ('test@test.com', 'test2@test.com') 
AND e.AddlEmail NOT IN ('test@test.com', 'test2@test.com')

包括 NULL 值:

SELECT *
FROM `doubleSelect`
WHERE (Email IS NULL or Email NOT IN ('email@email.com'))
AND (AddlEmail IS NULL or AddlEmail NOT IN ('email@email.com'))

关于mysql - 当值不存在于两列中时选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12185431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com