On Monday, March 28, 2005 21:07, Homam S.A. wrote:

> MySQL seems to let me use the LIMIT clause in both
> parts of a UNION ALL query, but as soon as I add an
> ORDER BY CLAUSE, it gives me a syntax error.
> 
> For example, this query executes fine:
> 
> SELECT * FROM A WHERE X = 1 LIMIT 1000
> UNION ALL
> SELECT * FROM B WHERE Y = 1 LIMIT 1000
> 
> But this returns an error:
> 
> SELECT X, Y FROM A WHERE W = 1 LIMIT 1000
> UNION ALL
> SELECT X, Y FROM B WHERE W = 1 LIMIT 1000
> ORDER BY X

(SELECT X, Y FROM A WHERE W = 1 LIMIT 1000)
UNION ALL
(SELECT X, Y FROM B WHERE W = 1 LIMIT 1000)
ORDER BY X

Without the parens, this looks like an order by on 
just the second query, and since this is after the 
LIMIT clause that is invalid. It should work fine 
with the parens.

> 
> Any way to let sort the result other than a temp
> table?
> 
> Thanks,
> 
> Homam

-- 
Tom Crimmins
Interface Specialist
Pottawattamie County, Iowa

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to