I have a result set like this:
UserName Action
-------------------
Joe Add
Joe Remove
Fred Add
Sam Add
Carl Remove
I only want to return the Add for Joe in this case. Add takes precedence. So if the user has an add record we only return that like.
Joe Add
Fred Add
Sam Add
Carl Remove
Not sure the best way to accomplish this.
>Solution :
If your real example is really as simple as your post, maybe consider something like:
SELECT username, MIN(action) action
FROM mytable
GROUP BY username
That will return one row per username (because of the GROUP BY). If there is some mix of "Add"/"Remove" actions, it will pick add (because "Add" will be the MIN). If there is only a "Remove" action (no "Add"s) it will use that.