p1.username
始终具有VB_user
表的外来值。问题是p2.username
的默认值为0
,而且它不是VB_user
表中的值。因此,如果我运行查询,它将仅显示p2.username
的值不为零的结果。如果p2.username
的价值0
会显示在我的搜索结果中,我怎么能这样做呢,因为VB_user.userid
没有0
可以,我还能吗什么东西?
换句话说,我希望能够显示p2.username
的结果,即使其值为0
。
这是我的疑问:
SELECT p.r1, p.r2, p.rounds, p.whenmatch, p.created, p.status, p.lid, p1.userid AS userid1, p1.username AS challenger, p2.userid AS userid2, p2.username AS challenged, p3.lname
FROM AB_league_match p
JOIN VB_user p1 on p.challenger = p1.userid
JOIN VB_user p2 on p.challenged = p2.userid
JOIN AB_league p3 on p.lid = p3.id
答案 0 :(得分:1)
SELECT p.r1, p.r2, p.rounds, p.whenmatch, p.created, p.status, p.lid, p1.userid AS userid1, p1.username AS challenger, p2.userid AS userid2, p2.username AS challenged, p3.lname
FROM AB_league_match p
JOIN VB_user p1 on p.challenger = p1.userid
LEFT JOIN VB_user p2 on p.challenged = p2.userid
JOIN AB_league p3 on p.lid = p3.id