Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 29th, 2007, 05:19 AM
estrela666 estrela666 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 2 estrela666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 49 sec
Reputation Power: 0
Question SQL Instruction for 3 tables

Hi! I'm new in the forum.
I have a doubt in a SQL instruction.

I have 3 tables. Books, Authors and Books_Authors.
This is the content of the tables:

Books:
1 - Book 1
2 - Book 2
3 - Book 3
4 - Book 4

Authors
1 - Author 1
2 - Author 2
3 - Author 3
4 - Author 4

Books_Authors
1 - 1
1 - 2
1 - 3
2 - 2
2 - 3

What I want, is a query that, when I choose Book number 1, and want to add more authors, just return the authors 3 and 4 because 1 and 2 are already been used.
I tried to do it with subquerys but don't know how!

Thanks in advance!

Reply With Quote
  #2  
Old March 29th, 2007, 08:12 AM
subeeshkn subeeshkn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 2 subeeshkn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 48 sec
Reputation Power: 0
query

SELECT dbo.xAuthor.AuthID
FROM dbo.xAuthor LEFT OUTER JOIN
dbo.xBooks_Authors ON dbo.xAuthor.AuthID = dbo.xBooks_Authors.AuthId AND dbo.xBooks_Authors.BookId = <book ID>
WHERE (dbo.xBooks_Authors.AuthId IS NULL)

this will return the unused author ids for the specified book ID

Reply With Quote
  #3  
Old March 29th, 2007, 10:20 AM
estrela666 estrela666 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 2 estrela666 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 49 sec
Reputation Power: 0
Thanks subeeshkn! It works!

Liliana

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > SQL Instruction for 3 tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT