我正在Sites
加入History
,并选择不在History
中的行。
$data = mysql_query("
select * from Sites
left join History
on Sites.URL = History.URL
where History.URL is null
order by Karma
");
问题是我想将WHERE UID = $uid
添加到表历史记录中,所以我只加入具有所述UID的行。
我想做这样的事情:
select * from Sites
left join History where UID = $uid
on Sites.URL = History.URL
where History.URL is null
order by Karma
这可能吗?我怎么能这样做?
答案 0 :(得分:3)
您可以将其添加到JOIN
子句:
select * from Sites
left join History ON UID = $uid
AND Sites.URL = History.URL
where History.URL is null
order by Karma
或WHERE
条款:
select * from Sites
left join History
AND Sites.URL = History.URL
where History.URL is null
and UID = $uid
order by Karma
注意:您应在此前面加上相应的表名称。我会,但你没有说明。
答案 1 :(得分:1)
是这样的:
select * from Sites s
Where Not Exists
(Select * From History
Where URL Is Null
And uid = $uid)
order by Karma
答案 2 :(得分:0)
尝试使用not exists
子句:
select * from Sites
where not exists (
select * from History
where UID = $uid
and Sites.URL = History.URL)
order by Karma