SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get recent record in duplicates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

k2radhakrishnan
Starting Member

India
1 Posts

Posted - 02/12/2014 :  01:31:07  Show Profile  Reply with Quote

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

Malaysia
961 Posts

Posted - 02/12/2014 :  04:04:51  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000