MySQL 需要 return table 使用 NULL id
MySQL need to return table with NULL id's
我有一个table和这个一样
id
number
id_user
1
001
NULL
2
002
NULL
1
001
13
id_user 是对用户 table 的 fk,但在分配用户时它应该为空
我怎样才能从 table 获得所有信息,有 id_user 和没有它?如果我创建
select number
from user, incident
where incident.id_user = user.id or incident.id_user is null
我得到了错误的信息
您应该使用左联接来包含空值:
select * from user left join incident on incident.id_user=user.id
或者:
select number
from user, incident
where incident.id_user(+) = user.id
我有一个table和这个一样
id | number | id_user |
---|---|---|
1 | 001 | NULL |
2 | 002 | NULL |
1 | 001 | 13 |
id_user 是对用户 table 的 fk,但在分配用户时它应该为空 我怎样才能从 table 获得所有信息,有 id_user 和没有它?如果我创建
select number
from user, incident
where incident.id_user = user.id or incident.id_user is null
我得到了错误的信息
您应该使用左联接来包含空值:
select * from user left join incident on incident.id_user=user.id
或者:
select number
from user, incident
where incident.id_user(+) = user.id