2012-11-30 176 views
0

我有訂單的數據庫,看起來大致是這樣的SQL多個查詢

ORDER ID | AMOUNT | FIRSTNAME | LASTNAME 
    1   50  JOHN  SMITH 
    2   60  PAUL  JOHNSON 
    3   20  FRANK  CAMERON 
    5   80  JOHN  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

請告訴我們你想要的查詢結果。 – LiuwkCn

回答

3

您可以用OR這樣的邏輯分離:

SELECT * FROM ORDERS 
WHERE 
(FIRSTNAME = "JOHN" AND LASTNAME = "SMITH") 
OR 
(FIRSTNAME = "PAUL" AND LASTNAME = "JOHNSON") 
3

你可以做這樣的事情

SELECT * 
FROM ORDERS 
WHERE concat(firstname, ' ', lastname) IN ('JOHN SMITH','PAUL JOHNSON')