Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how get rid of dupes in inner joins

Status
Not open for further replies.

pandatime

Programmer
Joined
Jan 29, 2010
Messages
92
Location
AU
Help.

I have a join across four tables. It basically "works" except that the number of rows in the result table is 4x the number that should be there (as a result of the joins that I'm apparently not doing correctly).

select d.c1, d.c2, nr3.c3
into myTable
from table1 t1
join table2 t2 on (t1.c1 = t2.c1)
join table2 t3 on (t2.c2 = t3.c2)
join table3 t4 on (t1.c3 = t4.c3)

I just need one result set. Just the intersection of the columns I need in the 4 tables.

I guess I am not thinking of this correctly. Please help :-)
 
actually nevermind i think the query is basically correct, the underlying data is actually different than what i thought hence the confusion
 
select column1, column2 from oldtable1name newtable1name
cross apply dbo.oldtable2name(newtable1name.oldtable2column1name);
go

or

select column1, column2 from oldtable1name newtable1name
outer apply dbo.oldtable2name(newtable1name.oldtable2column1name);
go

would do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top