开发者

SQL join ON not equal in Mysql

I have two tables. Both contains question id field. I want to get all records from first table that are not present in second one. I don't want to use开发者_JAVA百科 "NOT IN" constrain as second table having more than 400000 records.


Try something like

SELECt  t1.*
FROM    Table1 t1 LEFT JOIN
        Table2 t2   ON  t1.questionID = t2.questionID
WHERE   t2.questionID IS NULL


Typically you would do this using a LEFT JOIN combined with a WHERE clause selecting every row where the joined table returns no results.

SELECT t1.*
FROM   Table1 t1
       LEFT OUTER JOIN Table2 t2 ON t2.ID = t1.ID
WHERE  t2.ID IS NULL


try:

select from t1
right join t2 on t2.id = t1.id where t2.id is null
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜