在 SQL 服务器中的多个列中应用不同

Applying distinct in multiple columns in SQL server

我试图通过一列(消息)获得不同的结果。我试过了

SELECT DISTINCT 
  [id], [message]
  FROM Example table
GROUP BY [message]

但它没有显示预期的结果。 请让我知道我该怎么做?

示例table:

  id | Message     | 
    --  ------------
     1 | mike       | 
     2 | mike       |
     3 | star       | 
     4 | star       |  
     5 | star       | 
     6 | sky        |
     7 | sky        | 
     8 | sky        |  

结果table:

id | Message     | 
--  ------------
 1 | mike       | 
 3 | star      |
 6 | sky       | 

按您希望唯一的列分组,并在另一列上使用聚合函数。您希望每条消息的最低 id,因此使用 MIN()

select min(id) as id,
       message
from your_table
group by message