select statement
Posted in 1999
Topics: SQL Development & Query Writing, Stored Procedures & SPL
Hi!
I have two tables: One with customer related information and one with
customer addresses.
I want to list the number of entries that every customer has in the
first table so what I did is:
select info.name, address.phone, count(info.id) from info, address whereinfo.name=address.name group by info.name
This works fine except that some of the customers in the info table
don't have entries in the address table and they don't get displayed.
How can I get include them into this select with a null value for
address.phone?
Thanks in advance.
Lueder
"Lüder Sachse" wrote:
> Hi!
>
> I have two tables: One with customer related information and one with
> customer addresses.
> I want to list the number of entries that every customer has in the
> first table so what I did is:
>
> select info.name, address.phone, count(info.id) from info, address where> info.name=address.name group by info.name
>
> This works fine except that some of the customers in the info table
> don't have entries in the address table and they don't get displayed.
> How can I get include them into this select with a null value for
> address.phone?
Remember, info is your key table here. Try:
SELECT info.name, address.phone, count(*)
FROM info, OUTER address
WHERE info.name = address.name
GROUP BY info.name, address.phone;
That should do the trick for you.
-Richard