SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Need help with my SQL select statements. Please!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dlmagers10
Starting Member

48 Posts

Posted - 10/11/2010 :  15:53:13  Show Profile  Reply with Quote
Suppose you have a table by the name of BOOK B columns including BOOK_CODE, TITLE, PUBLISHER_CODE, TYPE, PRICE, PAPERBACK.

Then you have another table called PUBLISHER P columns including PUBLISHER_CODE, PUBLISHER_NAME, CITY

Question:
List the book title for each book that has the type PSY and that is published by Berkley Publishing?

I am working with multiple tables.

I need someone to help me and explain maybe. Please.

tkizer
Almighty SQL Goddess

USA
36823 Posts

Posted - 10/11/2010 :  15:55:21  Show Profile  Visit tkizer's Homepage  Reply with Quote
Please post what you have so far.

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

Subscribe to my blog
Go to Top of Page

dlmagers10
Starting Member

48 Posts

Posted - 10/11/2010 :  15:56:57  Show Profile  Reply with Quote
SELECT TITLE
FROM BOOK
WHERE EXISTS
(SELECT *
FROM PUBLISHER P
WHERE TITLE = 'Berkley'
and TYPE = 'PSY');
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36823 Posts

Posted - 10/11/2010 :  15:58:42  Show Profile  Visit tkizer's Homepage  Reply with Quote
Use a JOIN instead, linking the PUBLISHER_CODE columns together.

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

Subscribe to my blog
Go to Top of Page

dlmagers10
Starting Member

48 Posts

Posted - 10/11/2010 :  15:59:04  Show Profile  Reply with Quote
SELECT TITLE
FROM BOOK
WHERE EXISTS
(SELECT *
FROM PUBLISHER P, book b
WHERE p.publisher_name = 'Berkley'
and b.TYPE = 'PSY');
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36823 Posts

Posted - 10/11/2010 :  16:01:15  Show Profile  Visit tkizer's Homepage  Reply with Quote
This will get you started:

select *
from BOOK b
join PUBLISHER p
ON b.PUBLISHER_CODE = p.PUBLISHER_CODE

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

Subscribe to my blog
Go to Top of Page

dlmagers10
Starting Member

48 Posts

Posted - 10/11/2010 :  16:06:39  Show Profile  Reply with Quote
Should I use an EXISTS?
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36823 Posts

Posted - 10/11/2010 :  16:08:33  Show Profile  Visit tkizer's Homepage  Reply with Quote
No, a join is all you need. You now just need to add your WHERE clause.

Please note that we will only assist you with your homework and not do your assignment for you. So I'm giving you hints as you need to complete this work.

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

Subscribe to my blog
Go to Top of Page

dlmagers10
Starting Member

48 Posts

Posted - 10/11/2010 :  16:11:15  Show Profile  Reply with Quote
Thank you very much Tara. This semester is definitely a struggle for me. I am in my second year of school trying to achieve my associates degree in Web Technologies. Thanks again.
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36823 Posts

Posted - 10/11/2010 :  16:12:42  Show Profile  Visit tkizer's Homepage  Reply with Quote
You're welcome.

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

Subscribe to my blog
Go to Top of Page

dlmagers10
Starting Member

48 Posts

Posted - 10/11/2010 :  22:06:50  Show Profile  Reply with Quote
Tara,

By the way, I wanted to let you know that I figured it out. I was using 'Berkley' as 'Publisher_code' when I should of used 'BP' in my where statement. The common factor was not Publisher_Name rather Publisher_code. I got the whole select statement as:

SELECT TITLE
FROM BOOK B
JOIN PUBLISHER P
ON B.PUBLISHER_CODE = P.PUBLISHER_CODE
WHERE P.PUBLISHER_CODE LIKE 'BP'
AND B.TYPE LIKE 'PSY';

which gave me the correct answer.

Thank you again for helping me.

DM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000