那麼有沒有一種方法,使這樣的:MySQL的左連接和失蹤行
表1
id -> PK
table1_id -> FK
id | name | table1_id
1,'test',NULL
2,'test2',NULL
3,'sub_val1',1
4,'sub_val2',1
select a.name
, b.name
from table1 a
left join table1 b
on a.id=b.table1_id
where a.table1_id is null;
這將返回類似:
test,sub_val1
test,sub_val2
test2,NULL
我想它的回報例如:
test,NULL
test,sub_val1
test,sub_val2
test2,NULL
有沒有辦法做到這一點?
你試圖執行什麼業務規則?您是否正在尋找一種方法來保證結果至少包含一行第二列爲NULL值的行? – BellevueBob