我有一个类似于此的订单数据库
ORDER ID | AMOUNT | FIRSTNAME | LASTNAME
1 50 JOHN SMITH
2 60 PAUL JOHNSON
3 20 FRANK CAMERON
5 80 JOHN JOHNSON
我有一个我需要提取订单的名单。对于这个例子,我们可以说“JOHN SMITH”和“PAUL JOHNSON”
我尝试过像这样的查询
SELECT * FROM ORDERS WHERE FIRSTNAME IN ("JOHN", "PAUL") AND LASTNAME IN ("SMITH", "JOHNSON")
但显然这并不是我想要的,因为它包括在内。我不知道该怎么做但我需要搜索类似
的内容WHERE FIRSTNAME,LASTNAME IN ("JOHN","SMITH";"PAUL","JOHNSON")
OR
WHERE (FIRSTNAME,LASTNAME) IN {("JOHN","SMITH")("PAUL","JOHNSON")}
显然我对SQL知之甚少,所以我对搜索内容的语法和术语感到困惑?
答案 0 :(得分:3)
您可以将逻辑与OR
分开,如下所示:
SELECT * FROM ORDERS
WHERE
(FIRSTNAME = "JOHN" AND LASTNAME = "SMITH")
OR
(FIRSTNAME = "PAUL" AND LASTNAME = "JOHNSON")
答案 1 :(得分:3)
你可以做这样的事情
SELECT *
FROM ORDERS
WHERE concat(firstname, ' ', lastname) IN ('JOHN SMITH','PAUL JOHNSON')