I have a problem that can be easily solved with the help of several tables, but for this I have only one table.
Consider the following database table
UserID UserName EmailAddress Source 3K3S9 Ben ben@myisp.com user SF13F Harry lharry_x@hotbail.com 3rd_party SF13F Harry reside@domain.com user 76DSA Lisa cake@insider.com user OL39F Nick stick@whatever.com 3rd_party 8F66S Stan myman@lol.com user
I need to select all the fields, but only each user once has one of their email addresses (the "largest" defined by the MAX () function). This is the result I am after ...
UserID UserName EmailAddress Source 3K3S9 Ben ben@myisp.com user SF13F Harry lharry_x@hotbail.com 3rd_party 76DSA Lisa cake@insider.com user OL39F Nick stick@whatever.com 3rd_party 8F66S Stan myman@lol.com user
As you can see, "Harry" is displayed only once with his "highest" email address corresponding to the "source"
Currently, we are grouping by UserID, UserName and using MAX () for EmailAddress and Source, but the maximum of these two fields does not always coincide, they must be from the same record.
I tried a different process, attaching the table to myself, but I managed to get the correct email address, but not the appropriate "source" for this address.
Any help would be appreciated as I tried to solve this problem for too long :)
sql database join
Nippysaurus
source share