c# - Get records on the base of one field which should distinct -


i have query like

    select distinct(a.createdon),        a.id id ,        u1.firstname createdbyfirstname,        u1.lastname auditdetail left join userprofile u1 on a.createdby = u1.userprofileid left join userprofile u2 on a.updatedby = u2.userprofileid 

this shows me records. , distinct createdon repeated in each records because records comming. want if createdon same in records first record or single record should come not all. i'm wrong?

enter image description here

you can use ranking function such row_number() give rank on each record every group.

with recordlist (     select  a.createdon,             a.id id ,             u1.firstname createdbyfirstname,              u1.lastname,             row_number() over(partition a.createdon order a.createdon) rn        auditdetail              left join userprofile u1                  on a.createdby = u1.userprofileid              left join userprofile u2                  on a.updatedby = u2.userprofileid ) select  createdon,         id,         createdbyfirstname,         lastname    recordlist   rn = 1 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -