Re: Counting records in related table
Use a LEFT JOIN.
SELECT * , (IF (traffic.field IS NULL, COUNT(*), 0)) AS traffic_count
FROM members LEFT JOIN traffic ON (members.id = traffic.member_id)
GROUP BY members.id
ORDER BY traffic_count
Where field is some arbitrary field in the traffic table. It will be NULL when there is no matching record in the traffic table for a given member.
Subject
Written By
Posted
Re: Counting records in related table
March 24, 2005 08:45AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.