2017-09-13 101 views
2

说我有一个表像这样:SQL选择只有一个条目

ID  Description 
1  A popular place to eat! 
1  A popular place to eat!! 
1  A popular place to eat!!! 
2  Lets go! 
2  Everyone, Lets go! 

而我只是想说明每个ID的一个,因为他们不相关的方式不同:

ID  Description 
1  A popular place to eat! 
2  Everyone, Lets go! 

我如何编写SQL查询来从表1生成表2?

+0

如果什么说明都在'相关way'不同列?这是你的情况的一个选项?在这种情况下你会做什么? –

回答

4

集团通过你想成为独一无二的,使用任何聚合功能的description柱像min()max()

select id, min(description) 
from your_table 
group by id