内部联接的对立面是什么?对于表格表Person (int PersonId, varchar PersoName, int AddrId),我想知道AddrId错误的Person中的行,但Address表中没有行。

最佳答案



OUTER联接,可以有以下三种选择:

  • 完整

  • This is a good visual representation of JOINs



    使用LEFT JOIN / IS NULL
       SELECT p.*
         FROM PERSON p
    LEFT JOIN ADDRESS a ON a.addrid = p.addrid
        WHERE a.addrid IS NULL
    

    使用不存在
    SELECT p.*
      FROM PERSON p
     WHERE NOT EXISTS(SELECT NULL
                        FROM ADDRESS a
                       WHERE a.addrid = p.addrid)
    

    使用NOT IN
    SELECT p.*
      FROM PERSON p
     WHERE p.addrid NOT IN (SELECT a.addrid
                              FROM ADDRESS a)
    

    关于sql - 与内部联接相反,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3420982/

    10-11 04:48