我有一个包含两列的表: col1 |列2
。我想选择其中 col2
为反对派空和 col1
并且只有一行重复行
我的 table :
// tablename [col1=integer | col2=varchar]
+-------+-------------+
| col1 | col2 |
+-------+-------------+
| 1 | anything1 |
| 2 | |
| 3 | anything3 |
| 3 | anything3 |
| 4 | anything4 |
| 5 | anything5 |
| 5 | anything5 |
| 6 | |
| 7 | anything7 |
+-------+-------------+
我想要这个输出:
// newtablename
+-------+-------------+
| col1 | col2 |
+-------+-------------+
| 1 | anything1 |
| 3 | anything3 |
| 4 | anything4 |
| 5 | anything5 |
| 7 | anything7 |
+-------+-------------+
我的查询:
select * from tablename where col2 <>'' group by col1
现在我想知道,如何通过 distinct
实现上述查询(而不是group by
)?
最佳答案
你的意思是:
select distinct col1,col2
from tablename
where col2 <>''
order by col1
关于mysql - 如何通过distinct实现group by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31014805/