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

后端 未结 6 1541
忘掉有多难
忘掉有多难 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:43

    This would select 4 in your case

    SELECT ID FROM TableA WHERE ID NOT IN (SELECT ID FROM TableB)
    

    This would delete them

    DELETE FROM TableA WHERE ID NOT IN (SELECT ID FROM TableB)
    

提交回复
热议问题