Let\'s say I have the following table:
category | guid
---------+-----------------------
A | 5BC2...
A | 6A1C...
B | 92A2...
Just cast it as a BINARY(16)
.
SELECT category, MIN(CAST(guid AS BINARY(16)))
FROM myTable
GROUP BY category
You can cast it back later if necessary.
WITH CategoryValue
AS
(
SELECT category, MIN(CAST(guid AS BINARY(16)))
FROM myTable
GROUP BY category
)
SELECT category, CAST(guid AS UNIQUEIDENTIFIER)
FROM CategoryValue