Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 join

Author  Topic 

tommich
Starting Member

4 Posts

Posted - 2012-01-16 : 09:04:02
Hello,
i have the following problem:
show the numbers of lends for every author(give also the the authors with 0 lends)
i have 3 tables:boeken(columns:boek_id,auteur_id,jaar,titel,cat_id,uitg_id),uitleen(uitlnr,boek_id,datum,klant_id)and auteur(auteur_id,naam).
I've maked the follow query:

select naam,COUNT(*)as uitleningen
from AUTEUR a
left join BOEKEN b on b.auteur_id=a.auteur_id and
(b.boek_id in(select boek_id from UITLEEN))
group by naam


It's almost ok;it gives me al the authors and the correct number of lends for the authors who have lend out a book,but for the authors who not have Lend out a book,it counts 1.
What can i do for making this:0.

singularity
Posting Yak Master

153 Posts

Posted - 2012-01-16 : 09:24:45
[code]
select naam, COUNT(*) count(boek_id) as uitleningen
from AUTEUR a
left join BOEKEN b on b.auteur_id=a.auteur_id and
(b.boek_id in(select boek_id from UITLEEN))
group by naam
[/code]



Go to Top of Page

tommich
Starting Member

4 Posts

Posted - 2012-01-16 : 13:08:54
This works,
thank you very much
Go to Top of Page
   

- Advertisement -