Re: UNION question - Mailing list pgsql-general

From Brandon Metcalf
Subject Re: UNION question
Date
Msg-id Pine.LNX.4.58L.0907101133520.6574@cedar.geronimoalloys.com
Whole thread Raw
In response to Re: UNION question  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
t == tgl@sss.pgh.pa.us writes:

 t> Brandon Metcalf <brandon@geronimoalloys.com> writes:
 t> > I tried moving the last group of WHERE, GROUP BY, and ORDER BY before
 t> > the UNION with the query it belongs to, but that results in a
 t> > different syntax error.

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

 t> (SELECT ... ORDER BY ...) UNION SELECT ...

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


Indeed.  It was the fact that I was trying to move the ORDER BY along
with WHERE and GROUP BY that was giving me grief.

Thanks.

--
Brandon

pgsql-general by date:

Previous
From: Brandon Metcalf
Date:
Subject: Re: UNION question
Next
From: Jeff Davis
Date:
Subject: Re: SELECT DISTINCT very slow