如果用户没有匹配的问题或答案,我有以下查询为每个字段返回NULL。请问您能告诉我如何防止这种情况发生?
谢谢!
SELECT u.id, u.first_name, u.last_name, u.email, u.username, COUNT( DISTINCT q.id ) AS `q_count` , COUNT( DISTINCT a.id ) AS `a_count`
FROM `users` AS u
INNER JOIN `questions` AS q ON u.id = q.uid
INNER JOIN `answers` AS a ON u.id = a.uid
WHERE u.username = 'max'
LIMIT 0 , 30
答案 0 :(得分:4)
使用left join
代替inner join
s