Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从数据记录为空的类型表中选择*_Mysql_Sql - Fatal编程技术网

Mysql 从数据记录为空的类型表中选择*

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

我需要一个记录,即使它应该返回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 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;