SELECT
name,MIN(id_num)
FROM YourTable
GROUP BY name
更新: id_num をランダムに選択したい場合は、これを試してみてください
WITH cte AS (
SELECT
name, id_num,rn = ROW_NUMBER() OVER (PARTITION BY name ORDER BY newid())
FROM YourTable
)
SELECT *
FROM cte
WHERE rn = 1
SELECT
name,MIN(id_num)
FROM YourTable
GROUP BY name
更新: id_num をランダムに選択したい場合は、これを試してみてください
WITH cte AS (
SELECT
name, id_num,rn = ROW_NUMBER() OVER (PARTITION BY name ORDER BY newid())
FROM YourTable
)
SELECT *
FROM cte
WHERE rn = 1