select a value where it doesn't exist in another table

后端 未结 6 1540
忘掉有多难
忘掉有多难 2021-02-04 23:09

I have two tables

Table A:

ID
1
2
3
4

Table B:

ID
1
2
3

I have two requests:

  • I want to
6条回答
  •  迷失自我
    2021-02-04 23:41

    select ID from A where ID not in (select ID from B);
    

    or

    select ID from A except select ID from B;
    

    Your second question:

    delete from A where ID not in (select ID from B);
    

提交回复
热议问题