showing also value '0' with aggregate count() - Mailing list pgsql-general

From Janning Vygen
Subject showing also value '0' with aggregate count()
Date
Msg-id 01092716514505.27858@janning
Whole thread Raw
Responses Re: showing also value '0' with aggregate count()
Re: showing also value '0' with aggregate count()
List pgsql-general
I need some help please,

i am having two simple tables:

# select * from sales;
 client_id | product
-----------+---------
         1 | toolbox
         1 | nails
         2 | nuts

# select * from clients;
 id | name
----+-------
  1 | peter
  2 | john
  3 | marc

now i want to show all client name and the count of the sales in one
table like this:

# select name, count(sales.client_id) from clients, sales where
sales.client_id = clients.id group by name;

 name  | count
-------+-------
 john  |     1
 peter |     2

works fine, but where is marc??? it should look like

 name  | count
-------+-------
 john  |     1
 peter |     2
 marc  |     0

who can i make it work??? i think i know why my select statement
doesnt work, because of the where clause marc will never join this
table because the condition will never be true... but how can i do
it??

i guess its very very simple, but i just cant manage it.

thanks in advance
janning

pgsql-general by date:

Previous
From: David Santinoli
Date:
Subject: PostgreSQL 7.1.3 RPMs for RedHat 6.2
Next
From: R Talbot
Date:
Subject: Dir /pgsql/lib Files?