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
 how to get recent record in duplicates

Author  Topic 

k2radhakrishnan
Starting Member

1 Post

Posted - 2014-02-12 : 01:31:07

hi, by executing this qry i will get below result ,in that TId is duplicates that is from that i want recent record with same result.
i want last one if TId comes duplicate record. any one ans pl

select sa.GrandTotal, sa.TId, sa.Id,sa.Date, pr.PName,
pr.PCode from Sales sa
Left Outer Join Product pr on sa.Pid = pr.Id where sa.GrandTotal is not null


GrandTotal TId Id Date PName PCode
200 1 2 2014-01-30 18:46:55.000 RK 100
560 2 5 2014-01-30 18:47:49.000 RK 100
420 2 6 2014-01-30 19:55:11.000 RK 100

Radhakrshnan

waterduck
Aged Yak Warrior

982 Posts

Posted - 2014-02-12 : 04:04:51
few way to do this, this is one of it

select
sa.GrandTotal,
sa.TId,
sa.Id,
sa.Date,
pr.PName,
pr.PCode

from Sales sa

Left Outer Join Product pr
on sa.Pid = pr.Id

where sa.GrandTotal is not null
and sa.Date = (select MAX(date) from Sales sb where sa.pid = sb.pid)
Go to Top of Page
   

- Advertisement -