我有两个字段,email
并且addlEmail
. 如果给定的电子邮件地址不在任一字段中,我需要一个仅选择记录的选择。
尝试对两列使用 NOT IN(返回Cardinality violation: 1241 Operand should contain 2 column(s):
:)
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'
)