2014-02-20 78 views
0

比方說,我有一個名爲students的表。不等於sql條件

欄目有:

student_id 
first_name 
last_name 
address 

在輸出中,我要排除具有「地址」或「地址,在這裏」的地址學生。

我試圖

SELECT * FROM students WHERE address <> 'address' OR address <> 'address, here'; 

這是行不通的。

它只與

SELECT * FROM students WHERE address <> 'address'; 

工作如何做到這一點?

+0

你在你的情況可能需要一個'和',而不是'或' –

+0

您可以使用不是也喜歡運營商在MySQL。你也可以在兩個條件之間寫AND運算符而不是OR運算符。 –

回答

0
SELECT * 
FROM students 
WHERE 
    address <> 'address' 
    AND 
    address <> 'address, here' 
0

試試這個:

SELECT * FROM students WHERE (address <> 'address' AND address <> 'address, here'); 
1

使用,取而代之的或

SELECT * FROM students WHERE address <> 'address' AND address <> 'address, here'; 

address <> 'address' OR address <> 'address, here'將永遠是正確的,因爲一個地址不能'address''address, here'在同一時間。

2

如何

SELECT * 
FROM students 
WHERE address NOT IN ('address','address, here') 
+0

我非常喜歡這個查詢的pythonicness! :d – exhuma