I have two fields, email and addlEmail. I need a select that only selects the record if a given email address is not in either field.
Attempt at using NOT IN with two columns (returns: 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')"
I have tried AND and OR, they do not work for obvious reasons.
For the sake of trying to be thorough:
$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
The query should only return rows 3 and 4.
Thanks for taking a look, and please let me know if you need further clarification.
Chris
EDIT:
Sample table in response to answer posted:
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);
Sample Query (does not return the last row, and it should):
SELECT *
FROM `doubleSelect`
WHERE Email NOT
IN (
'email@email.com'
)
AND AddlEmail NOT
IN (
'email@email.com'
)
Try this