Selecting primary keys that do not have foreign keys in another table

前端 未结 3 1488
囚心锁ツ
囚心锁ツ 2021-02-05 19:53

For simplification, I have two tables related with one to many using a foreign key, for example:

Users table:
id
name

Actions table:
id
user_id
<
3条回答
  •  迷失自我
    2021-02-05 20:21

    SELECT u.id
    FROM users u
    LEFT JOIN actions a
       ON a.user_id = u.id
    WHERE a.user_id IS NULL
    

提交回复
热议问题