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

后端 未结 4 894
抹茶落季
抹茶落季 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:53

    SELECT a FROM t1 WHERE a=10 AND B=1
    UNION
    SELECT a FROM t2 WHERE a=11 AND B=2
    ORDER BY 1 LIMIT 10;
    

    if you need sort by more fields just add the number of the field, ORDER BY 1, 2, 3 LIMIT 10;

提交回复
热议问题