Reputation: 24491
I have the following query which returns NULL for each field if there are no matching questions or answers for the user. Please can you tell me how I can prevent this from happening?
Thanks!
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
Upvotes: 2
Views: 46