1.distinct 单列
select distinct(a) from tableA;
这个比较简单,没什么可说的。
2.distinct多列
select distinct a,b,c from tableA;
select a,b,c from tableA group by a,b,c
3.另外一种的distinct多列
select distinct a from tableA; select distinct b from tableA; select distinct c from tableA;
select distinct(a) || ' a' from tableA union all select distinct(b) || ' b' from tableA union all select distinct(c) || ' c' from tableA
这样就达到了一条语句查询出所有结果的目的。后面拼接的字符串是为了标识这个值属于哪个字段。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/204959.html原文链接:https://javaforall.net
