SQL join ON not equal in Mysql

前端 未结 3 1446
眼角桃花
眼角桃花 2021-02-19 23:35

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 \"NOT IN\" constrain as s

相关标签:
3条回答
  • 2021-02-19 23:57

    try:

    select from t1
    right join t2 on t2.id = t1.id where t2.id is null
    
    0 讨论(0)
  • 2021-02-20 00:04

    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
    
    0 讨论(0)
  • 2021-02-20 00:06

    Try something like

    SELECt  t1.*
    FROM    Table1 t1 LEFT JOIN
            Table2 t2   ON  t1.questionID = t2.questionID
    WHERE   t2.questionID IS NULL
    
    0 讨论(0)
提交回复
热议问题