I know this'll look scary :
 
select distinct book.bid, title, price, condition, author.name, edition from book left 
join purchase on book.bid=purchase.bid left join student on 1 = 1 left join edition on 
edition.bid = book.bid left join author on 1 = 1 left join author_book on 1 = 1 where 
purchase.bid is null and book.bid = author_book.bid and author_book.aid = author.aid 
and gender=2 and title like '%java%' order by price
 
The reason for the so many left joins is to avoid the nullification of a result in the 
situation where a table is empty (Yes, normal joins give an empty result if any tables 
participating in the join are empty). I want to make sure that the book is not 
purchased, so I left join to the purchase table, then choose the results with 
purchase.bid = NULL.
 
I'm getting the following result
 
TitleEditionAuthorPriceConditionjava how to program2deitel & deitel11 JDUsed
 
Which is good, except that this book is owned by a male. Gender = 1, regardless of the 
complexity of the above query. How am I getting a result with a male when my where 
clause contains a gender=2 (female)condition??? Is it a bug? or have I gotten rusty on 
SQL?

Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam

Reply via email to