如果未找到任何行,则查询失败

时间:2012-05-10 21:58:07

标签: mysql inner-join

如果用户没有匹配的问题或答案,我有以下查询为每个字段返回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

1 个答案:

答案 0 :(得分:4)

使用left join代替inner join s