Reputation: 1643
I have data of the below format and need help in filtering the output. tried multiple combinations but couldn't get through
the data I have is
User Id Comments Status Date Set#
123 First Edit E 22-Feb-17 0
123 First Edit E 22-Feb-17 55
123 First Edit X 22-Feb-17 55
123 First Edit X 22-Feb-17 55
123 Second Edit X 22-Feb-17 55
123 Second Edit X 22-Feb-17 55
if the text between two rows is same I should select first occurrence of that row and if the text is different I have to select both.
The output should look like
User Id Comments Status Date Set#
123 First Edit E 22-Feb-17 0
123 Second Edit X 22-Feb-17 55
Upvotes: 1
Views: 49
Reputation: 1269853
I think you just want row_number()
:
select t.*
from (select t.*,
row_number() over (partition by userId, comments order by date) as sequm
from t
) t
where seqnum = 1;
Note: You say "select first occurrence of that row". SQL tables represent unordered sets, so there is no first occurrence. This answer assumes that date
actually has a time component that specifies the ordering you intend.
Upvotes: 2