Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Duplicate Record results on 2 one to many tables!!!

$
0
0
Hi,I hope i'm doing this correctly.I have 3 TablesTableA - TAID, Name, LastNameTableB - MaleFriendsName, MaleFriendsLastName [One to many]TableC - FemaleFriendsName, FemaleFriendsLastName [one to many]A query returns duplicate results from TableB as well as TableCTableB and TableC have nothing in common and should not interfere with each other.with TwoTables as (select a.QuickSpec as QuickSpecId, a.BusinessName as SpecBusinessName, a.Location as SpecLocation, a.Topic as SpecTopic, b.SpecIDAnalysis as BId, b.ImageField as BCol1, b.ImageInfo as BCol2, rn = row_number() over (partition by a.QuickSpec order by (select null))from QuickSpec a inner join Analysis b on (QuickSpec = SpecIDAnalysis))select QuickSpecId, SpecBusinessName, SpecLocation, SpecTopic, BId, BCol1, BCol2, c.SpecIDMultiple as CId, c.Image1 as CCol1, c.Image2 as CCol2from TwoTables tt left outer join QuickSpecMultiple c on (tt.QuickSpecId = c.SpecIDMultiple and tt.rn = 1);Resultset returns duplicate values on TableB AND only for 1 record in the results [As per Lynn examples]

Viewing all articles
Browse latest Browse all 3145

Trending Articles