select distinct over specific columns

Posted by Midhat on Stack Overflow See other posts from Stack Overflow or by Midhat
Published on 2010-04-26T08:48:21Z Indexed on 2010/04/26 8:53 UTC
Read the original article Hit count: 156

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql