So, everything is in the title.
I am looking to merge the result of two requests and order the result together (as in, not one after the other). => I was thinking of applying a union and ordering them. It didn't work.
I looked around like here on Stack or here developpez (!!french website). I've tried the different examples and suggestions, but no success. It seems from what I read that it's because I am working on Mysql.
Anyway, here are my attempts, and the results.
My original 2 requests:
SELECT * FROM user_relation WHERE from_user_id = 1
List item
SELECT * FROM user_relation WHERE to_user_id = 1
This result of a list made of the result of the first select (ordered by index key) followed by the result of 2nd select ordered by index key.
Attempt 1:
(SELECT * FROM user_relation WHERE from_user_id = 1 ORDER BY trust_degree)
UNION
(SELECT * FROM user_relation WHERE to_user_id = 1 ORDER BY trust_degree)
The request ran, but the result was the same as the original request: result of first select (ordered by index key) followed by the results of the second request.
Attempt 2:
(SELECT * FROM user_relation WHERE from_user_id = 1 ORDER BY trust_degree)
UNION
(SELECT * FROM user_relation WHERE to_user_id = 1 ORDER BY trust_degree)
ORDER BY trust_degree
Request ran, result same as attempt 1, but with a warning in the Mysql logic:
(this type of close has been already analysed (ORDER BY))
Attempt 3:
(SELECT * FROM user_relation WHERE from_user_id = 1
UNION
SELECT * FROM user_relation WHERE to_user_id = 1)
ORDER BY trust_degree
Did not run, but an error #1064 - syntax error near UNION.
Attempt 4:
SELECT *
FROM (
(SELECT * FROM user_relation WHERE from_user_id = 1)
UNION
(SELECT * FROM user_relation WHERE to_user_id = 1)
)
ORDER BY trust_degree
Did not run, and a nice list of 6 errors. Any suggestions?
OR
? :)