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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 DUPLICATING RESULTS

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-03-12 : 22:20:04
I have a query that Is creating duplicate values example
select
sd.vp, sd.rep,sd.create_dt ed.address, ep.sales
from table1 sd
inner join table2 ed
on sd.id = ed.id
inner join table 3 ep
on ed.id = ep.id

where vp = 'Mark Smith'
group by sd.vp, sd.rep, ed.address, ep.sales

the problem with this query is that for each vp it should ONLY have a DISTINCT rep with their total sales for the dAY however this querry is producing the vp with the same rep and same sale amount duplicating 3 times.
MARK SMITH candy brown 123 somwher st 21000
MARK SMITH candy brown 123 somwher st 21000
MARK SMITH candy brown 123 somwher st 21000



a distinct would be good but can I place the distinct by the sd.rep? so that it returns the rep only once

MARK SMITH candy brown 123 somwher st 21000

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2014-03-13 : 01:08:12
select Distinct
sd.vp, sd.rep,sd.create_dt ed.address, ep.sales
from table1 sd
inner join table2 ed
on sd.id = ed.id
inner join table 3 ep
on ed.id = ep.id

Veera
Go to Top of Page
   

- Advertisement -