On Fri, Jun 15, 2012 at 08:10:20AM -0400, Kevin Benson scratched on the wall: > On Fri, Jun 15, 2012 at 5:56 AM, YAN HONG YE <yanhong...@mpsa.com> wrote: > > > > select * from hbc order by cmc desc limit 10 > > union > > select * from hbc where qph>0 > > union > > select * from hbc where hctl=1 > > > > this sql cmd cause the error: > > order by clause should come after union not before > > > > http://www.sqlite.org/lang_select.html > > ORDER BY and LIMIT clauses may only occur at the end of the entire compound > SELECT.
You can, however, convert the first SELECT from a clause in the compound statement to a sub-select within the first clause. In that case the ORDER BY/LIMIT will be enfoced by the sub-select. You should also collapse the second and third clause into a single SELECT... "select * from hbc where aph>0 or hctl=1" That will also avoid duplicate rows if a specific row meets both conditions. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable." -- Angela Johnson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users