Let's say I have the following table:
category | guid
---------+-----------------------
A | 5BC2...
A | 6A1C...
B | 92A2...
Basically, I want to do the following SQL:
SELECT category, MIN(guid)
FROM myTable
GROUP BY category
It doesn't necessarily have to be MIN. I just want to return one GUID of each category. I don't care which one. Unfortunately, SQL Server does not allow MIN or MAX on GUIDs.
Of course, I could convert the guid into a varchar, or create some nested TOP 1 SQL, but that seems like an ugly workaround. Is there some elegant solution that I've missed?
SELECT DISTINCT category FROM myTable
instead? Or do you really need an arbitrary GUID for each category? – Sammysamoan