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

前端 未结 3 1500
囚心锁ツ
囚心锁ツ 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:30

    select u.id
    from users u
    left outer join actions a on a.user_id = u.id
    where a.user_id is null
    

提交回复
热议问题