What I have is basically a problem which is easily solved with multiple tables, but I have only a single table to do it.
Consider the following database table
UserID UserName EmailAddress Source
3K3S9 Ben [email protected] user
SF13F Harry [email protected] 3rd_party
SF13F Harry [email protected] user
76DSA Lisa [email protected] user
OL39F Nick [email protected] 3rd_party
8F66S Stan [email protected] user
I need to select all fields, but only who each user once along with one of their email addresses (the "biggest" one as determined by the MAX() function). This is the result I am after ...
UserID UserName EmailAddress Source
3K3S9 Ben [email protected] user
SF13F Harry [email protected] 3rd_party
76DSA Lisa [email protected] user
OL39F Nick [email protected] 3rd_party
8F66S Stan [email protected] user
As you can see, "Harry" is only shown once with his "highest" email address the correcponding "source"
Currently what is happening is that we are grouping on the UserID, UserName, and using MAX() for the EmailAddress and Source, but the max of those two fields dont always match up, they need to be from the same record.
I have tried another process by joining the table with itself, but I have only managed to get the correct email address but not the corresponding "source" for that address.
Any help would be appreciated as I have spent way too long trying to solve this already :)