How to query SQL Table and remove duplicate rows from a result set

前端 未结 3 2035
感动是毒
感动是毒 2020-12-21 19:26

I know this is simple...

Please advise on how I can get a result set of rows 1, 9, 18, and 21 (based on the attached image)??

Thanks,

Brad

<

3条回答
  •  佛祖请我去吃肉
    2020-12-21 19:33

    If the rows are truly distinct across every column, then you can use SELECT DISTINCT.

    Since you are using SQL Server you can also use row_number() to return one row for each ThreatId:

    select ThreatId,
      ThreatTopClient,
      ...
    from
    (
      select ThreatId,
        ThreatTopClient,
        ...,
        row_number() over(partition by ThreatId order by ThreatMLSeq) rn
      from xThreatCA
      where ThreatMLSeq <> N'' 
        and ID <> 0
    ) d
    where rn = 1
    order by ThreatMLSeq
    

提交回复
热议问题