开发者

Applying distinct to single column

I have a sql query

select  distinct 
Process.ReportLogProcessID as [Process.ReportLogProcessID],
Process.ProcessTitle as [Process.ProcessTitle],
CAST(User0.Primar开发者_高级运维yEmail AS nvarchar(max)) as [Process_Contacts.IsPrimaryContact]

  from
ReportProcess as Process inner join
ReportProcessContact as ReportProcessContact0 on
    ((ReportProcessContact0.SessionID = Process.SessionID)) left outer join
[User] as User0 on
    ((ReportProcessContact0.ReferenceID = User0.UserID)) left outer join
[Group] as Group0 on
    ((ReportProcessContact0.ReferenceID = Group0.GroupID and
ReportProcessContact0.ReferenceType = 2))

 order by
[Process.ProcessTitle] asc

and it give below result

Applying distinct to single column

if you see it returns two rows with the same 'Process Title'-'Testing123' is there any way I can distinct this in spite of whatever be the 'Process Contact'.

Is there any way to distinct the result on the base of particular column?


In your query [Process_Contacts.IsPrimaryContact] column have different emails for both records. If you remove that column then only it will distinct records.

UPDATE : You can try like :

select  
       Process.ReportLogProcessID as [Process.ReportLogProcessID], 
       Process.ProcessTitle as [Process.ProcessTitle], 
       MAX(CAST(User0.PrimaryEmail AS nvarchar(max))) as [Process_Contacts.IsPrimaryContact] 
from ReportProcess as Process 
inner join ReportProcessContact as ReportProcessContact0 on 
      ((ReportProcessContact0.SessionID = Process.SessionID)) 
left outer join [User] as User0 on 
      ((ReportProcessContact0.ReferenceID = User0.UserID)) 
left outer join [Group] as Group0 on 
      ((ReportProcessContact0.ReferenceID = Group0.GroupID and 
      ReportProcessContact0.ReferenceType = 2)) 

group by Process.ReportLogProcessID, Process.ProcessTitle
order by [Process.ProcessTitle] asc 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜