MYSQL UNION ORDERING

后端 未结 4 542

Is it possible to order the first enquiry and keep the rows returned as first and not order the second enquiry. (If that makes sence)

An example of my current enquir

4条回答
  •  醉梦人生
    2021-01-12 07:44

    You'd need to introduce an artificial sort key. Something like:

    SELECT
        *, 1 as SortKey
    FROM 
        Devices
    WHERE
        Live = 'true'
        AND Category = 'apple'
    UNION
    SELECT
            *, 2 as SortKey
        FROM
            Devices
        WHERE
            DeviceLive = 'true'
    ORDER BY SortKey, ListOrder
    

提交回复
热议问题