首頁  >  問答  >  主體

mysql - 下面語句用left join 還是用not in?

實作:查詢a中沒有關聯b的記錄

1、select id from a left join b on a.id = b.aid where b.id is null and status = 1
2、select id from a where id not in (select aid from b) and  status = 1

那種更好,或有其他的方式,請大神留下答案

PHP中文网PHP中文网2691 天前1006

全部回覆(2)我來回復

  • 高洛峰

    高洛峰2017-06-06 09:54:24

    不存在正確答案

    雷雷

    回覆
    0
  • 習慣沉默

    習慣沉默2017-06-06 09:54:24

    我想使用 not exists

    淺談sql中的in與not in,exists與not exists的區別

    回覆
    0
  • 取消回覆