2015-09-01 68 views
1

我需要與工會有兩個條件,選擇從表中的數據,從表中的數據,或者任何用於表如何有兩個條件選擇

name  special 

    Deepak   s 
    mukesh   v 
    dinesh   s 
    girgesh  v 
    Deepak   s 
    mukesh   v 
    dinesh   s 
    girgesh  v 
    Deepak   s 
    mukesh   v 
    dinesh   s 
    girgesh  v 

查詢獲取數據...

SELECT NAME FROM student WHERE special = "s" LIMIT 2 
UNION 
SELECT NAME FROM student WHERE special = "v" LIMIT 2 

但它在聯合之前只給出第一個條件... 如何從單個表中獲取兩個不同的條件數據

+0

使用'union all' –

+0

SELECT nAME FROM student WHERE special =「s」OR special =「v」LIMIT 2 –

回答

2

每個MySQL's documentation on UNION

通過或LIMIT應用於爲了將個人選擇,將子句封閉SELECT


括號內所以,你想使用:

(SELECT NAME FROM student WHERE special = "s" LIMIT 2) 
UNION 
(SELECT NAME FROM student WHERE special = "v" LIMIT 2) 
0

正如@Burned Buffen在評論中提到的:

SELECT NAME FROM student WHERE special = "s" or special = "v" LIMIT 2