Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to find the tables to join ? Expand / Collapse
Author
Message
Posted Tuesday, January 29, 2013 9:39 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 10, 2013 3:36 AM
Points: 16, Visits: 41


Hello,

I am beginner in T-SQL.

I need to find the tables to the join between the table "Product" table and the "Customer" of the database AdventureWorks2012.

Any idea ?


Thank you.
Post #1413151
Posted Tuesday, January 29, 2013 10:29 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 12,923, Visits: 12,342
salmita (1/29/2013)


Hello,

I am beginner in T-SQL.

I need to find the tables to the join between the table "Product" table and the "Customer" of the database AdventureWorks2012.

Any idea ?


Thank you.


Customers have no direct tie to Products. Are you wanting to maybe see the Products that a customer has ordered?


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1413184
Posted Tuesday, January 29, 2013 11:41 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 10, 2013 3:36 AM
Points: 16, Visits: 41
I wanna display the names of the customers along with the product names that they have purchased !!

Post #1413219
Posted Tuesday, January 29, 2013 12:20 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 12,923, Visits: 12,342
salmita (1/29/2013)
I wanna display the names of the customers along with the product names that they have purchased !!



So what table(s) do you think you might need for this?


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1413241
Posted Tuesday, January 29, 2013 12:25 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 10, 2013 3:36 AM
Points: 16, Visits: 41
that's my question??? i don't know which ones can do the join ?
Post #1413247
Posted Tuesday, January 29, 2013 12:36 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 12,923, Visits: 12,342
salmita (1/29/2013)
that's my question??? i don't know which ones can do the join ?


Well think about what you are asking. You are starting with knowing that you need customer and product information. You have that part down but think about what gets you from one to the other. What happens when a customer purchases something?


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1413256
Posted Thursday, January 31, 2013 6:20 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:38 AM
Points: 13,755, Visits: 28,147
If you really don't know the structure, then you need to hope that all the tables have foreign keys. You can look at the dependencies of one of the tables, say Products, to see which tables are related to it. Then you can walk the chain to figure out how to connect the tables you want. Here's a great article from SQL Tips that shows a ton of ways to get this done.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1414068
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse