I have a table which contains some denormalized data something like the following (fake to simplify my question):
Book Table
ID, Title, Author-Name, Publisher-Name, Category
In another table I have something like the following:
Author Table
ID, Author-Name, Address
Publisher Table
ID, Publisher-Name, Address
Assume that Publisher-Name
and Author-Name
are always unique.
Desired Result-Set
Now, all I want to do is create a query that creates a result-set that includes :
1. all columns from Book table
2. Author.ID
3. Publisher.ID
The final result set would look something like the following:
Result-set Columns
ID, Title, Author-Name, Author.ID as [AuthorID], Publisher-Name, Publisher.ID as [PublisherID] Category
Let's say there are two rows in the Book Table, then the result-set would have two rows which include the appropriate values for the Author.ID and Publisher.ID, because the lookup has been done in the query and returned in the result-set.
What I've Tried : join
I've tried using various joins but I always get more rows than just two rows
, because the join seems to join on the Publisher.ID
AND the Author.ID
and I get 1 row
for each of them which ends up giving me 4
rows instead of 2
.
Sample Data
Books
1, 'All The Time', 'Fred Smith', 'Big Pub Co.', 'non-fiction'
2, 'Biggest Title Ever', 'John Jones', 'Small Pub Co.', 'fiction'
Authors
100, 'Fred Smith', 'Yukon, AK'
101, 'John Jones', 'Happy, VT'
Publishers
300, 'Big Pub Co', 'Angry, IL'
301, 'Small Pub Co', 'Someplace, IN'
Expected Result-Set
1, 'All The Time', 'Fred Smith', 100, 'Big Pub Co.', 300, 'non-fiction'
2, 'Biggest Title Ever', 'John Jones', 101, 'Small Pub Co.' 301, 'fiction'