Re: UNION question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Brandon Metcalf <brandon(at)geronimoalloys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: UNION question
Date: 2009-07-10 16:29:00
Message-ID: 24751.1247243340@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Brandon Metcalf <brandon(at)geronimoalloys(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Brandon Metcalf 2009-07-10 16:33:50 Re: UNION question
Previous Message Hartman, Matthew 2009-07-10 16:27:44 Re: UNION question