I’m trying to write a SQL UNION that works on both MySQL and SQLite.
(select_clause_A) UNION (select_clause_B)
SQLite doesn’t like the parentheses for those statements (see the
‘compound operater’):
http://www.sqlite.org/lang_select.html
Unfortunately I think MySQL requires parentheses if you use an
‘order by’ clause:
http://dev.mysql.com/doc/refman/5.0/en/union.html
Does anyone happen to know which database is following the SQL standard? I suppose its possible they both are…
There’s no need for brackets/parenthesis in a UNION statement.
MySQL is the only one I’m aware of at this moment, which allows you to define
ORDER BYandLIMITclauses specific to each query as long as the query is enclosed in brackets — standard SQL only allows aORDER BYfor the final result. TheGROUP BYandHAVINGclauses are specific to each query that makes up the UNION’d statement.MySQL supports:
…which will cause no end of grief if you want/need to port to other databases.
Standard SQL only allows: