0

我有一个大致像这样的订单数据库

   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")

或者

WHERE (FIRSTNAME,LASTNAME) IN {("JOHN","SMITH")("PAUL","JOHNSON")}

显然我对 SQL 知之甚少,所以我被困在搜索什么的语法和术语上?

4

2 回答 2

3

您可以使用这样的分隔逻辑OR

SELECT * FROM ORDERS
WHERE 
(FIRSTNAME = "JOHN" AND LASTNAME = "SMITH")
OR
(FIRSTNAME = "PAUL" AND LASTNAME = "JOHNSON")
于 2012-11-30T02:11:24.267 回答
3

你可以做这样的事情

SELECT *
FROM ORDERS
WHERE concat(firstname, ' ', lastname) IN ('JOHN SMITH','PAUL JOHNSON')
于 2012-11-30T02:13:53.670 回答