|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! ![]() |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Thanks subeeshkn! It works!
Liliana |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > SQL Instruction for 3 tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|