Php 使用JOIN包含空值
我的目标是合并两个表(预测和用户_分数)的结果,这样我就有了所有在比赛中得分的用户和没有得分的用户,但他们都参与了池(poolid=110) 预测Php 使用JOIN包含空值,php,mysql,Php,Mysql,我的目标是合并两个表(预测和用户_分数)的结果,这样我就有了所有在比赛中得分的用户和没有得分的用户,但他们都参与了池(poolid=110) 预测 predid | matchid | ueserid | points | -------------------------------------------- 1 121 8 1 2 122 8 2 3
predid | matchid | ueserid | points |
--------------------------------------------
1 121 8 1
2 122 8 2
3 122 10 3
用户评分
id | poolid | userid |
------------------------------
1 110 8
2 110 10
3 111 8
4 111 10
结果应该是这样的:
| matchid | ueserid | points | poolid
--------------------------------------------
121 8 1 110
null 10 null 110
这是我尝试过的几个问题:
SELECT * FROM predictions LEFT JOIN user_score on predictions.userid = user_score.userid WHERE predictions.matchid=121 and user_score.poolid=110
SELECT * FROM predictions RIGHT JOIN user_score on predictions.userid = user_score.userid WHERE predictions.matchid=121 and user_score.poolid=110
此查询不适用于我的SQL版本Apache/2.4.26(Win32)OpenSSL/1.0.2l PHP/5.6.31/数据库客户端版本:libmysql-mysqlnd 5.0.11-dev-20120503/
SELECT * FROM predictions FULL OUTER JOIN user_score on predictions.userid = user_score.userid WHERE predictions.matchid=121 and user_score.poolid=110
我需要帮助:)使用左连接,并将条件
matchid=121
放入ON子句中:
select p.matchid, s.userid, p.points, s.poolid
from user_score s
left join predictions p
on p.userid = s.userid
and p.matchid = 121
where s.poolid = 110
演示:
您也可以使用RIGHT JOIN方法,但ON子句中必须包含matchid=121
条件
使用左连接,并将条件
matchid=121
放入ON子句中:
select p.matchid, s.userid, p.points, s.poolid
from user_score s
left join predictions p
on p.userid = s.userid
and p.matchid = 121
where s.poolid = 110
演示:
您也可以使用RIGHT JOIN方法,但ON子句中必须包含matchid=121
条件
MySQL不支持完全外部连接MySQL不支持完全外部连接