Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql question 1

Status
Not open for further replies.

megabyte214

Programmer
Nov 7, 2001
40
US
Below is a query and it is not displaying the count for authors who do not have any books. I understand why, but I do not know how to fix it. I need it to return 0 for authors with no books.

Code:
select lastname, count(ba.isbn) from author as a, bookauthor as ba, book as b where b.isbn = ba.isbn and ba.authorid = a.authorid group by a.lastname asc;

Thanks in advance.
 
Code:
select a.lastname, count(ba.isbn) 
from author as a left join  bookauthor as ba
on ba.authorid = a.authorid
group by a.lastname

I don't see why you need to join the book table. Also, using asc or desc on group by is not standard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top