
[英]How to get all distinct words of a specified minimum length from multiple columns in a MySQL table?
[英]How to get multiple distinct columns from a table?
我需要从基于行的表中获取多个不同的值。 目前我正在使用两个不同的查询来获取不同的值。
select distinct a from table;
select distinct b from table;
有没有办法在单个查询中做到这一点。 我正在使用 JDBCTemplate 从这两个查询中获取数据。 单个查询是否会比这两个单独的查询更高效。 我正在使用 postgresDB。
我想出了以下单个查询,但我相信这不是高性能的。
select e1.a,e2.b from table t join (select distinct a,id from table)e1 on e1.id=t.id join (select distinct b,id from table)e2 on e2.id=t.id ;
两个单一的查询可能是最好的方法。 你也可以这样做:
select distinct 'a' as which, a from table
union all
select distinct 'b', b from table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.