Mysql 从数据记录为空的类型表中选择*
及 我需要一个记录,即使它应该返回null的记录的类型不存在。因此,患者2应该带回2条记录,即使只有1条记录Mysql 从数据记录为空的类型表中选择*,mysql,sql,Mysql,Sql,及 我需要一个记录,即使它应该返回null的记录的类型不存在。因此,患者2应该带回2条记录,即使只有1条记录 Colours ID| patientID | date |Type 1 | 1 | 2019 |1 2 | 1 | 2019 |2 3 | 2 | 2018 |1 但是,我需要患者2为日期返回所有带有空值的颜色。目前正在获取: Select Title,date from Colours Left Join Types On Colo
Colours
ID| patientID | date |Type
1 | 1 | 2019 |1
2 | 1 | 2019 |2
3 | 2 | 2018 |1
但是,我需要患者2为日期返回所有带有空值的颜色。目前正在获取:
Select Title,date from Colours Left Join Types On Colours.Type = Types .ID Where patient.ID = 1
{
patient1:[{
Title: blue
date : 2019
},
{
Title: red,
date : 2019
}]
}
然而,我需要:
Select Title,date from Colours Left Join Types On Colours.Type = Types .ID Where patient.ID = 2
patient:[{
Title: blue
date : 2018
}]
我想你需要一个
左连接
:
patient:[{
Title: blue
date : 2018
},
{
Title: red,
date : null
}]
}
patient:[{
Title: blue
date : 2018
},
{
Title: red,
date : null
}]
}
select t.Title, c.date
from types t left join
Colours c
On c.Type = t.ID and c.patientID = 2;