I have the following query in mysql:
SELECT DISTINCT re1.name as name1, re2.name as name2
FROM Rating ra1 JOIN Reviewer re1
ON re1.rID = ra1.rID
CROSS JOIN
Reviewer re2 JOIN Rating ra2 ON re2.rID = ra2.rID
WHERE ra1.mID = ra2.mID
AND re1.rID != re2.rID
AND re1.rID > re2.rID
ORDER BY name1, name2;
This is the retrieved data:
How can I order the obtained rows alphabetically? (ie, in second row, to switch Brittany and Chris Position)
Thanks
CodePudding user response:
Use the functions LEAST()
and GREATEST()
:
SELECT DISTINCT
LEAST(re1.name, re2.name) AS name1,
GREATEST(re1.name, re2.name) AS name2
FROM ...