3
Answers

Book are not sold out by using join

Seshadri M

Seshadri M

7y
229
1

which book are not sold out in Book table and given Book name


Book
BID Bookname pricecode
1 Harry potter AB01
2 Sheldon AB01
3 Dan brown AB01
4 Cindrella AB01
 
Sold
ID BID sold date
1 1 9/13/2017
2 2 9/12/2017
3 4 9/15/2017
4 8 9/19/2017
 
select Bookname from Book Join sold  on Book.BID=Sold.BID where sold date IS null 
--i am not getting expected output 
 
Answers (3)
2
Himanshu Jaiswal

Himanshu Jaiswal

NA 204 10 7y
Hi Seshadri,
 
There are multiple way to pull the book those are not sold yet: 
 
1) SELECT B.Bookname FROM Book B LEFT JOIN sold S  on B.BID=S.BID where S.solddate IS NULL
 
2) SELECT B.Bookname FROM Book B  where B.BID NOT IN  (SELECT S.BID FROM sold  S)
 
 
0
Poonam Bhosale

Poonam Bhosale

NA 73 3 7y

Hi  Seshadri,

You will get a right answer by executing following query      
 
select b.Bookname
from Book b
where b.BID not in(select s.BID from Sold s where b.BID=s.BID ) 
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
You can try like this
  1. SELECT DISTINCT B.Bookname   
  2. FROM Book B INNER JOIN Sold S   
  3. ON B.BID != S.BID