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.
| Author |
Topic |
|
DMarmolejos
Yak Posting Veteran
65 Posts |
Posted - 2008-07-18 : 15:30:59
|
| Table1 T1colacolbcolcTable2 T2colacoleTable3 T3colacolfTable4 T4colccolzWhen I try to group all of them I get repeating rows..This is what I had:SelectFROM Table1 T1, Table2 T2, Table3 T3, Table4 T4WHERE T1.colz = T4.colz AND T2.cola = T3.cola AND T3.cola = T1.colaMy question is how is the correct way to join these tables so I dont get repeating rows?Any help is appreciatedThank you |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-18 : 15:37:56
|
| You've edited your post since I've posted mine, so I'll respond to your edit. You are getting repeating rows as there are multiple rows satisfying the join condition. To prevent this, you can use group by although it would be best if you showed us some sample data and expected output so that we can help you better.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2008-07-18 : 15:44:04
|
| T1 does not have "colz" column. Post the query as you run it. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-19 : 01:48:18
|
| posting some sample data from your tables will also help |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-19 : 02:29:31
|
You can 1) Add a DISTINCT keyword2) Rewrite all JOINs as derived tables to eliminate duplicate dataSELECT *FROM Table1 AS t1INNER JOIN Table3 AS t3 ON t3.colA = t1.colAINNER JOIN Table2 AS t2 ON t2.colA = t3.colAINNER JOIN Table4 AS t4 ON t4.colC = t1.colC Please remember we do not have access to you system,and based on the very little information you have given us, we have no other chance than guessing.WE don't even know what is stored in the tables! E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|