2

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

1 回答 1

4

使用left joins 代替inner joins

于 2012-05-10T21:59:59.437 回答