I want to query a table with multiple combined fields in an IN
clause.
Example: find all records with "john doe" and "marc smith", but ignore all other persons..
SELECT * FROM persons
WHERE firstname IN ('john', 'marc')
AND lastname IN ('doe', 'smith');
But I don’t want to find jane;doe
for example. But how can I combine multiple columns inside the IN clause?
3
Answers
I discovered mysql supports this out of the box:
You might consider creating a sort of lookup table that contains the first- and lastname combinations you’re interested in.
Then query something like this:
In order to speed up the process, I would create a unique index on the first/lastname within that lookup table.
You can just use the above concat function which would help you to eliminate different combination of name and surname.
Hope this helps !!!!