如何在MySQL中选择多个匹配值映射列的记录?

时间:2016-10-15 19:50:10

标签: mysql

我有以下3列表:

+----+---------+------------+ | ID | First | Last | +----+---------+------------+ | 1 | Maurice | Richard | | 2 | Yvan | Cournoyer | | 3 | Carey | Price | | 4 | Guy | Lafleur | | 5 | Steve | Shutt | +----+---------+------------+

如果我想在(Maurice,Guy)中寻找所有人,我可以select * from table where first in (Maurice,Guy)

如果我只想查找Maurice Richard,我可以select * from table where first = "Maurice" and last = "Richard"

如何制作地图,多个数组?

[ [Maurice, Richard] [Guy,Lafleur] [Yvan,Cournoyer] ]

如果我有任意数量的条目,我就无法构建一个长复合体where (first = "Maurice" and last = "Richard") or (first = "Guy" and last = "Lafleur") or ....

我如何做到where (first, last) in ((Guy,Lafleur),(Maurice,Richard))的道德等同?

1 个答案:

答案 0 :(得分:1)

你可以像描述它那样做:

SELECT *
FROM mytable
WHERE (first, last) IN (('Guy','Lafleur'),('Maurice','Richard'))

Demo here