apply “ORDER BY” on a “UNION” (Mysql)

后端 未结 4 877
抹茶落季
抹茶落季 2021-01-01 21:35

Good Day. So, everythign 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

4条回答
  •  庸人自扰
    2021-01-01 21:50

    To expand on my comment:

    SELECT * into #tempTable FROM (
       SELECT * FROM user_relation WHERE from_user_id = 1
       UNION
       SELECT * FROM user_relation WHERE to_user_id = 1
    )
    as x
    
    SELECT * FROM #tempTable ORDER BY trust_degree
    DROP TABLE #temptable
    

提交回复
热议问题