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

它返回与特定用户关联的所有剪辑。但是,我很难编写一个完全相反的查询;选择与该用户无关的所有剪辑。

我试过这个:

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

确实会返回与该用户无关的剪辑,但它会丢失与任何用户无关的剪辑。

如果可以的话请帮忙 :)

4

3 回答 3

1
 $line = @mysql_query("SELECT DISTINCT * FROM clips WHERE clips.id 
 NOT IN (SELECT clipid FROM userclips WHERE userid='$id') ORDER BY clips.title");
于 2012-06-29T12:24:08.300 回答
1

返回与特定用户无关的所有剪辑和用户信息,其 id 已传递

SELECT * FROM clips, userclips 
WHERE userclips.userid!='$id'
ORDER BY clips.title
于 2012-06-29T12:25:41.847 回答
0

我将使用 not in 进行此类查询

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)
于 2012-06-29T12:24:30.203 回答