开发者

select distinct over specific columns

开发者 https://www.devze.com 2022-12-28 08:40 出处:网络
A query in a system I maintain returns QID AID DATA 12x 12y 56t 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 开发者_运维问答sel

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


If you don't care which DATA will be selected, GROUP BY is nice, though using ungrouped and unaggregated columns in SELECT clause of a GROUP BY statement is MySQL specific and not portable.

0

精彩评论

暂无评论...
验证码 换一张
取 消