Re: UNION question - Mailing list pgsql-general

From Tom Lane
Subject Re: UNION question
Date
Msg-id 24751.1247243340@sss.pgh.pa.us
Whole thread Raw
In response to UNION question  (Brandon Metcalf <brandon@geronimoalloys.com>)
Responses Re: UNION question
List pgsql-general
Brandon Metcalf <brandon@geronimoalloys.com> writes:
> I tried moving the last group of WHERE, GROUP BY, and ORDER BY before
> the UNION with the query it belongs to, but that results in a
> different syntax error.

I think that's probably what you want to do.  What you're missing is
you need parentheses to put an ORDER BY into an arm of a UNION:

(SELECT ... ORDER BY ...) UNION SELECT ...

Otherwise it wants to consider the ORDER BY as applying to the UNION
output.

            regards, tom lane

pgsql-general by date:

Previous
From: "Hartman, Matthew"
Date:
Subject: Re: UNION question
Next
From: Brandon Metcalf
Date:
Subject: Re: UNION question