0

2つのテーブルで次の問題が発生します。

table1には

  • uid
  • 名前

table2には

  • id
  • 名前

条件を満たさないすべての行をtable1から削除するSQLスクリプトを作成したい

table1.uid = table2.id
4

2 に答える 2

1
delete from table1 t1
where not exists (select 1 from table2 where id = t1.uid)

また

delete from table1
where uid not in (select id from table2)
于 2012-10-15T11:55:15.820 に答える
1
DELETE FROM table1 
WHERE NOT EXISTS
( select table2.name
  from table2
  where table1.uid = table2.id);
于 2012-10-15T11:56:29.317 に答える