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
 SELECT statement using Multiple Tables

Author  Topic 

dlmagers10
Starting Member

48 Posts

Posted - 2010-10-11 : 16:42:50
The question is Find the b.book_code and b.title for each book located in branch number 2 and written by author 20.

SELECT BOOK_CODE, TITLE
FROM BOOK B, BRANCH H, AUTHOR A
WHERE H.BRANCH_NUM = '2'
AND A.AUTHOR_NUM = '20';

For some reason I am not coming up with what I need to come up with:

0180 A Deepness in the Sky
0189 Magic Terror
0200 The Stranger
0378 Venice
079X Second Wind
0808 The Edge
1351 Dreamcatcher: A Novel
1382 Treasure Chests
138X Beloved
2226 Harry Potter and the Prisoner of Azkaban
2281 Van Gogh and Gauguin
2766 Of Mice and Men
2908 Electric Light
3350 Group: Six People in Search of a Life
3743 Nine Stories
3906 The Soul of a New Machine
5163 Travels with Charley
5790 Catch-22
6128 Jazz
6328 Band of Brothers
669X A Guide to SQL
6908 Franny and Zooey
7405 East of Eden
7443 Harry Potter and the Goblet of Fire
7559 The Fall
8092 Godel, Escher, Bach
8720 When Rabbit Howls
9611 Black House
9627 Song of Solomon
9701 The Grapes of Wrath
9882 Slay Ride
9883 The Catcher in the Rye
9931 To Kill a Mockingbird

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-11 : 16:44:56
See my JOIN query in your other topic. You need to specify the join conditions, which you haven't done in your query. SQL doesn't know what to join on even if the column names are the same in the tables. You have to explicitly tell it what to join on.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-11 : 16:49:33
http://www.builderau.com.au/program/sqlserver/soa/SQL-basics-Query-multiple-tables/0,339028455,320267371,00.htm


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -