Assume I have a table with the following entries:
ID VALUE CATEGORY
-----------------------
1 10 A
1 20 S
2 30 S
2 10 A
3 50 A
4 40 C
5 60 B
How do I write a SQL query so that for each ID if category S exists, it should output that record, but if it doesn’t exist then it should output the entry which exists.
So in my example I would like to achieve the following result:
ID VALUE CATEGORY
-----------------------
1 20 S
2 30 S
3 50 A
4 40 C
5 60 B
I found a more elegant solution 🙂