I have the following bit of code, and it works so far:
SELECT
[id],
COALESCE ([Company], [LastName] + ', ' + [FirstName]) as Customer
FROM [some_database].[dbo].[some_table]
ORDER BY Customer
However, I’d like to use the DISTINCT keyword to eliminate duplicate “Customer” entries. Is this possible? I’ve tried it a few different ways, but to no avail.
If you have multiple customer entries with the same name, you have to pick one ID for a given name. Here’s an example of picking the most recently created (ie
max()), but you may want the first created (iemin()):EDITED: Sorry… GROUP BY 2, not 1