I have the following result from a query in mysql (headers: depicao, arricao):
EDDH, EDDK
EDFH, EDDL
EDDS, EDDH
EDDK, EDDH
My problem is now, that I just want one of the rows, IF the data exist in the correlation “EDDH – EDDK” AND “EDDK – EDDH”.
The query for this result is something like this:
SELECT DISTINCT p.depicao, p.arricao FROM xyz WHERE xxyyzz = 1
Thanks for your help!
Advertisement
Answer
Order the columns in a consistent way with GREATEST
and LEAST
, then use SELECT DISTINCT
to remove duplicates.
SELECT DISTINCT GREATEST(depicao, arricao) as col1, LEAST(depicao, arricao) AS col2 FROM xyz WHERE ...