简体   繁体   中英

select distinct over specific columns

A query in a system I maintain returns

QID AID DATA
1   2   x
1   2   y
5   6   t

As per a new requirement, I do not want the (QID, AID)=(1,2) pair to be repeated. We also dont care what value is selected from "data" column. either x or y will do.

What I have done is to enclose the original query like this

SELECT * FROM (<original query text>) Results group by QID,AID

Is there a better way to go about this? The original query uses multiple joins and unions and what not, So I would prefer not to touch it unless its absolutely necesary

如果您不在乎将选择哪个DATA ,那么GROUP BY很好,尽管在GROUP BY语句的SELECT子句中使用未分组和未聚合的列是MySQL特定的,并且不可移植。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM