Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Confused with linking tables

Author  Topic 

mrgr8avill
Starting Member

16 Posts

Posted - 2007-12-13 : 19:54:11
Hi and thanks for taking the time to read this. I get really confused really quickly when it comes to table linking, and I think I am doing it the hard way. I am going to show my stupidity and ask if there is a better way than what I do, because it takes a LOT of querying and seems like a huge waste.

In reality, I have about 20 tables to join like this, but I'm going to use three for the example:

"Main" Table
AcctNo Name Height Weight
1 Bob 1 3
2 Phil 2 1
3 Jim 1 5
4 Lisa 2 2

"Height" Table
HeightID HeightName
1 Giant
2 Tall
3 Medium
4 Short

"Weight" Table
WeightID W_Name
1 Skinny
2 Normal
3 Overweight
4 Obese


What I have been doing is:

SELECT
Main.AcctNo,
Main.Name,
Height.HeightName,
Weight.WeightName
FROM
Main
INNER JOIN Height ON
Height.HeightID = Main.Height
INNER JOIN Weight ON
Weight.WeightID = Main.Weight
WHERE Main.AcctNo < 3


My question: is doing 20 INNER JOINS really the best way to do this with 20 tables, or is there some other way to link Main.Height to Height.HeightID that is less intensive?

Thanks again for reading, and in advance for any information or insight you can provide.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-13 : 20:07:52
Joins are the way to go.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -