我有一个正在运行的以下查询(以及两个名为topic和topic_dataitem_relation的表):
SELECT * FROM omid.topic as t
WHERE t.ID NOT IN (
SELECT tdr.TopicID FROM omid.topic_dataitem_relation As tdr
WHERE tdr.DataitemID = 37
);
但我希望当我使用加入时我无法达到相同的结果:
SELECT distinct *
FROM omid.topic as t
left join omid.topic_dataitem_relation As tdr
ON t.ID != tdr.TopicID
WHERE tdr.DataitemID = 37;
如果可以加入,可以帮助我吗?(提前谢谢)
答案 0 :(得分:0)
JOIN也是一个条件,所以要应用其他条件,必须使用AND,而 您的查询将是:
SELECT *
FROM omid.topic as t
JOIN omid.topic_dataitem_relation As tdr
ON t.ID != tdr.TopicID
AND tdr.DataitemID = 37; /* Your WHERE BECOME AND */
/* AND condition2 = value 2*/
/* AND ..... */