List:General Discussion« Previous MessageNext Message »
From:David Christian Date:May 20 1999 4:37pm
Subject:Re: SQL Question - OUTER JOIN? (newbie)
View as plain text  
>> I have two tables:
>> 
>> (1) members - member_id, name, phone, address
>> (2) entries - entry_id, member_id, title, description, date
>> 
>> I want to show a list of all members and, alongside each member, I want to show a
> sum of the total number of entries they have in the entries table.
>>
>The solution of your problem is called LEFT JOIN.
>Just substitute the JOIN with a LEFT JOIN and it works:
>SELECT 
>	m.name
>	, m.phone
>	, m.address
>	, count(e.entry_id)
>FROM 
>	members m
>	LEFT JOIN entries e
>WHERE 
>	m.member_id = e.member_id
>GROUP BY 
>	m.name

Christian, that gave me a MySQL syntax error, but I took your cue and got it working like
this:

SELECT
     m.name
     , m.phone
     , m.address
     , count(e.entry_id)
FROM
     members m
     LEFT JOIN entries e ON m.member_id = e.member_id
GROUP BY
     m.name

Works like a charm! :-)

Thanks very much for your help.

David


Thread
SQL Question - OUTER JOIN? (newbie)David Christian19 May
  • Re: SQL Question - OUTER JOIN? (newbie)Christian Mack19 May
    • Re: SQL Question - OUTER JOIN? (newbie)David Christian20 May