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
 IN operator and EXISTS operator.Need some guidance

Author  Topic 

dlmagers10
Starting Member

48 Posts

Posted - 2010-10-22 : 10:27:39
Ok trying to find the book title for each book written by author num 18. Trying to use the IN operator.

BOOK TABLE INCLUDES: BOOK_CODE, TITLE, PUBLISHER_CODE, TYPE, PRICE, PAPERBACK

AUTHOR TABLE INCLUDES: AUTHOR_NUM, AUTHOR_LAST, AUTHOR_FIRST

WROTE TABLE INCLUDES: BOOK_CODE, AUTHOR_NUM

INVENTORY TABLE INCLUDED: BOOK_CODE, BRANCH_NUM, ON_HAND

THIS IS WHAT I HAVE THUS FAR:

SELECT TITLE
FROM BOOK B
WHERE B.AUTHOR_NUM IN
(SELECT AUTHOR_NUM
FROM AUTHOR
WHERE AUTHOR_NUM = '18');



Hey just someone would just please help to understand. I do not want the answer. Just a littl help answering this question. I kinda need the answer this in an IN operator then I need to turn around and answer in an EXISTS operator in my query.

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-10-22 : 11:08:58
Maybe this will help... http://sqlinthewild.co.za/index.php/2009/08/17/exists-vs-in/

Since the table B doesn't have the AuthorNum column, your IN needs to compare Book code (in the books table) against book code in the Wrote table, and the filter for author num can be done against that table. (so the IN subquery needs to be against only the Wrote table)

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -