Click here to Skip to main content
14,545,215 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to Join 4 separate tables together using the Adventureworks 2014 database. The output I'm looking for is a table containing the bike sales (Product category) per territoryID (country)

These two tables don't contain a foreign key so I've managed to find a connection in the database tables between 4 tables that I think might work.I'm not sure as these are linked with 3 foreign keys

The [Sales].[SalesOrderHeader] table and the[Sales].[SalesTerritory] tables both contain the TerritoryID foreign key they can be joined together

https://i.stack.imgur.com/WCnLo.png[^]

Then theres the SalesOrderDetail table which contains the foreign key 'SalesOrderID' which can also be linked to the SalesOrderHeader table

https://i.stack.imgur.com/uvZr9.png[^]

and then theres the Product ID table with the Product ID key that can be linked to the SalesOrderDetail table

https://i.stack.imgur.com/rlG9o.png[^]

Does anyone know a query that can run this. Any help would be appreciated

What I have tried:

I have tried doing singular joins
Posted
Updated 19-May-20 8:18am
Comments
0x01AA 19-May-20 14:16pm
   
1. Joining tables in an SQL does not require that foreign keys are available
2. What you mean with " singular joins"?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The existence (or lack thereof) of foreign keys has nothing directly to do with JOINs. If you have one it MAY be a field to join the two tables but not necessarily.

What you need to do is determine the proper fields for JOINing the tables. This may be all three to a single central field, a daisy chain form table to table, and mixtures in-between. So solve this puzzle to give you the data groupings you require.

You are JOINing data in columns - that's it.
   
Comments
0x01AA 19-May-20 14:31pm
   
"You are JOINing data in columns - that's it"
You are JOINing data in columns between tables - that's it.
... and a +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100