In DQL - how I do DESC at Union

  • I need to do- two select at union, and the result at DESC ( from the newest to oldest)

    I will be very glad if anyone can help me.

    thenks.

    ofir.

  • you can use order by at the end of the querry

  • ORDER BY applies to the result of the UNION not the individual SELECT's so you can do this

    SELECT 1 AS [Result]

    UNION

    SELECT 2 AS [Result]

    ORDER BY Result DESC

    Or did you mean you wanted each SELECT to be ORDERED separately from the other

    Far away is close at hand in the images of elsewhere.
    Anon.

  • put both your query in an inline view then order the view...

    Select * from

    (

    SELECT a, b, c from TableA

    UNION

    SELECT a, b, c from Table B

    ) RESULTS

    ORDER BY a DESC

    Hope this helps.

    Regards,

    TBS.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply