-2

Consider the below table

KEY    WO#    Parts   Name
77     11     1       aa
77     11     2       aa
81     12     2       bb
82     9      3       cc

Now i want to write a query for my report so that whenever theres a duplicate RKEY i want it to ignore it even though the number of parts in the duplicate RKEY are different and proceed with the next RKEY. Is this possible

End result

KEY    WO#    Parts   Name
77     11     1       aa
81     12     2       bb
82     9      3       cc
Saaharjit Singh
  • 125
  • 1
  • 1
  • 14

2 Answers2

2

This has been asked and answered literally hundreds of times. But it is faster to type out a solution than find an existing answer.

select [KEY]
    , [WO#]
    , Parts
    , Name
from
(
    select [KEY]
        , [WO#]
        , Parts
        , Name
        , RowNum = ROW_NUMBER() over (partition by KEY order by Parts)
    from YourTable
) x
where RowNum = 1
Sean Lange
  • 33,028
  • 3
  • 25
  • 40
-1

EatPeanutButter is correct: If you use the 'group by' command on 'Key', only the first instance of 'Key' will be shown in the end result.

select * from table group by Key;
BSMP
  • 4,596
  • 8
  • 33
  • 44