2012-06-29 39 views
1
$line = @mysql_query("SELECT * FROM clips, userclips 
WHERE userclips.userid='$id' AND 
userclips.clipid=clips.id ORDER BY clips.title"); 

它返回與特定用戶關聯的所有剪輯。然而,我很難試圖寫出一個完全相反的查詢。選擇所有不與該用戶關聯的剪輯。PHP MYSQL對面選擇

我已經試過這樣:

$line = @mysql_query("SELECT DISTINCT * FROM clips, userclips 
WHERE userclips.userid!='$id' AND userclips.clipid=clips.id ORDER BY clips.title"); 

這確實返回與該用戶相關聯的剪輯,但它忽略不與任何用戶相關聯的剪輯。

請幫助,如果你能:)

+2

您應該調查不使用mysql_ *函數。至少去PDO或者mysqli_ *。 – Leigh

+0

是否要返回一個特定的剪輯或所有與用戶無關的剪輯 –

+1

感謝所有回覆的人,這是我第一次使用stackoverflow,有點被所有有用的迴應所淹沒。感謝大家。 :) – user1491119

回答

1
$line = @mysql_query("SELECT DISTINCT * FROM clips WHERE clips.id 
NOT IN (SELECT clipid FROM userclips WHERE userid='$id') ORDER BY clips.title"); 
+0

輝煌,做了我所需要的非常感謝。 – user1491119

0

我會不會使用這種查詢

Select * 
From clips 
Where id NOT IN (SELECT clips.id 
        FROM clips, userclips 
        WHERE userclips.userid = '$id' 
        AND userclips.clipid = clips.id 
        ORDER BY clips.title) 
1

返回所有剪輯和用戶信息不與特定的用戶相關聯的,其ID通過

SELECT * FROM clips, userclips 
WHERE userclips.userid!='$id' 
ORDER BY clips.title