选择另一个表中没有外键的主键

Sai*_*akR 10 mysql sql database one-to-many

为简化起见,我有两个表使用外键与一对多相关,例如:

Users table:
id
name

Actions table:
id
user_id
Run Code Online (Sandbox Code Playgroud)

一个用户可能有很多动作.我需要一个sql select来返回在actions表中没有user_id值的用户id.

Users Table:
id      name
1       John
2       Smith
3       Alice

Actions Table:
id      user_id
1       3
2       1
Run Code Online (Sandbox Code Playgroud)

所以我需要一个返回用户ID 2(Smith)的SQL查询,因为外键值不包含id 2

我尝试了以下SQL,但它返回所有用户ID:

SELECT users.id from users left join actions on actions.user_id is null
Run Code Online (Sandbox Code Playgroud)

jue*_*n d 15

select u.id
from users u
left outer join actions a on a.user_id = u.id
where a.user_id is null
Run Code Online (Sandbox Code Playgroud)