views:

99

answers:

1

A SQL statement can give a list of the most popular gifts that are sent in a Social application, all the way to the ones that are sent 1, or 2 times, but it won't include the Zeros.

I think the same goes for getting the list of the most popular Classes that students are registering for, when the registration process for all students is 10 days and now it is the 3rd day. Again, we get the count but the Zeros are not there.

Is there a simple SQL statement that can show the whole list, including all the zeros?

+2  A: 
SELECT g.gift_id, COUNT(v.gift_id) AS given_count
FROM gifts AS g
LEFT OUTER JOIN gifts_given AS v USING (gift_id)
GROUP BY g.gift_id;
Bill Karwin