三つの方法でAテーブルを調べたデータはBテーブルのデータに現れませんでした。

646 ワード

Aテーブル(users)
フィールド:
  uid int not null primary key,
  uname nvarhar(30)not null
B表(results)
フィールド:
  rid int not null primary key、
  uid int not null(users表のuidを参照)
照会AテーブルのデータはBテーブルに表示されていません。
1.not inを使う

select * from users where uid not in (select uid from results)
2.left joinを使う

select u.* from users as u left join results as r on u.uid = r.uid where r.uid is null
3.not existsを使う

select u.* from users as u where not exists(select * from results where uid = u.uid)