Heim  >  Fragen und Antworten  >  Hauptteil

mysql – Soll ich in der folgenden Anweisung Left Join verwenden oder nicht?

Implementierung: Datensätze in a abfragen, die nicht mit b in Zusammenhang stehen

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

Welches ist besser oder wenn es einen anderen Weg gibt, hinterlassen Sie bitte eine Antwort

PHP中文网PHP中文网2691 Tage vor1009

Antworte allen(2)Ich werde antworten

  • 高洛峰

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

    not exists正解

    select id from a where not exists (select 1 from b where a.id=b.aid) and status = 1

    Antwort
    0
  • 習慣沉默

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

    我想使用 not exists

    浅谈sql中的in与not in,exists与not exists的区别

    Antwort
    0
  • StornierenAntwort