0

I have the following problem with two tables:

table1 has

  • uid
  • name

table2 has

  • id
  • name

I want to write a sql script that deletes all rows from table1 which don't meet the condition

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 回答