'Multi column WHERE IN AND
I am currently using MySQL (5.7) to query a table of members.
When I do a query like:
SELECT fname, lname, added
FROM Members
WHERE ((fname, lname) IN (('firstname one', 'lastname one'), ('firstname one', 'lastname one')));
It works as expected and a list of members first names, last names, and the date they were added is shown.
But if I want to narrow down when a member was added, e.g.
SELECT fname, lname, added
FROM Members
WHERE ((fname, lname) IN (('firstname one', 'lastname one'), ('firstname two', 'lastname two')))
AND added => '2014-01-01 00:00:00' AND added <= '2014-06-01 00:00:00';
I get the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=> '2014-01-01 00:00:00' AND added <= '2014-06-01 00:00:00'' at line 3
If I try an IN clause on a single column:
...
WHERE fname IN ('firstname one', 'firstname two')
AND added => '2014-01-01 00:00:00' AND added<= '2014-06-01 00:00:00'
It works OK. So the issues seems to be with an IN clause over two (or more) columns.
Could someone please point out what I am doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|