I would like to select one record if there are many status. example, if there is the same user and status A, B, C, select only record ‘A’. If there is the same user and status B, C, choose B, if there is only one status, bring that one.
======================= User Name Status ======================= 123 | Alice | B 123 | Alice | A 123 | Alice | C 124 | Mark | C 125 | Jonh | B 126 | Pate | B 126 | Pate | C
expected RESULT
======================= User Name Status ======================= 123 | Alice | A 124 | Mark | C 125 | Jonh | B 126 | Pate | B
Could anyone help to suggest? Thank you
Advertisement
Answer
group by
does what you need in that case, and it’s a bit easier than analytical functions:
select user, name, min(status) as status from yourtable group by user, name;