[英]Return all rows from both queries/tables with left join
I have two subqueries on which I am doing a join, first one returns following data: 我有两个要进行连接的子查询,第一个返回以下数据:
array (size=110)
0 =>
array (size=3)
'scans' => string '7' (length=1)
'bonus_points' => string '0' (length=1)
'date' => string '2017-06-13' (length=10)
1 =>
array (size=3)
'scans' => string '20' (length=2)
'bonus_points' => string '0' (length=1)
'date' => string '2017-06-14' (length=10)
second one: 第二个:
array (size=21)
0 =>
array (size=2)
'redeems' => string '1' (length=1)
'date' => string '2017-06-14' (length=10)
If I do a left join on those two like so: 如果我像这样对这两个进行左连接:
LEFT JOIN query2 ON query2.date=query1.date;
I get the following: 我得到以下内容:
array (size=110)
0 =>
array (size=4)
'scans' => string '7' (length=1)
'bonus_points' => string '0' (length=1)
'date' => null
'redeems' => null
1 =>
array (size=4)
'scans' => string '20' (length=2)
'bonus_points' => string '0' (length=1)
'date' => string '2017-06-14' (length=10)
'redeems' => string '1' (length=1)
Everything is as I want it to be, except that the left query doesn't always have the same dates as the right query and then the result is 'date' => null
. 一切都如我所愿,只是左查询并不总是与右查询具有相同的日期,然后结果是'date' => null
。
How can I keep the data from both queries? 如何保留两个查询的数据?
从左侧表中选择date
列,而不是从右侧(连接)中选择date
列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.