如何在两列中查询多个值

时间:2016-01-19 06:27:13

标签: mysql

我想检查两个或更多特定值,如firstname和lastname是否在我的数据库中。

Select * from client_info 
where (first_name = "John" and last_name ="Smith")
and   (first_name = "Donald" and last_name ="Trump")
and   (first_name = "Baracj" and last_name ="Obama")

提前致谢

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

Select * from client_info 
      where (first_name = "John" and last_name ="Smith")
           or (first_name = "Donald" and last_name ="Trump")
           or (first_name = "Baracj" and last_name ="Obama")

答案 1 :(得分:0)

执行此查询,如果结果为> = 2,那么表中有两行

SELECT COUNT(*) FROM (SELECT DISTINCT first_name, last_name FROM client_info
                      WHERE (first_name = "John" AND last_name ="Smith")
                         OR (first_name = "Donald" AND last_name ="Trump")
                         OR (first_name = "Baracj" AND last_name ="Obama")) AS ci