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
 Help with a join query please?

Author  Topic 

BluefoxBoy
Starting Member

2 Posts

Posted - 2013-09-07 : 03:52:49
I have tables named books,supplier, publisher & reason_deleted. The publisher and supplier data are in publisher and supplier tables,books data in books table with publisher and supplier id, and reason_deleted table contains id of books that were deleted. When I write the query

select b.idno,b.title,pub.pub_name,dr.reason,dr.date_deleted,sup.sup_name
from books b inner join reason_deleted dr on dr.book_id=b.idno
inner join publisher pub on b.pub_id=pub.idno inner join supplier sup on b.sup_id=sup.idno

I get results. But among them, some books which are missing supplier/publisher are not shown (means supplier id or publisher id is null in the books table). I need all the books which were deleted whether or not they have supplier or publisher. How can I achieve this?

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2013-09-07 : 04:02:59
change the last two "inner join" to "left outer join"
Go to Top of Page

BluefoxBoy
Starting Member

2 Posts

Posted - 2013-09-07 : 06:46:05
Dank You
Go to Top of Page
   

- Advertisement -