On 15 Jun 2012, at 10:56am, 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 Yes. The UNION clauses you're using tell SQLite which rows you want. The order of those rows does not matter, so there's no point in putting an ORDER BY clause on one of the SELECTs. If you need ORDER BY on the above statement you would normally do it like this > select * from hbc > union > select * from hbc where qph>0 > union > select * from hbc where hctl=1 > order by cmc desc limit 10 However, that statement doesn't make sense. Because it starts with /all/ the rows in table hbc, and then adds in some of the rows in table hbc. But since it already has /all/ the rows in table hbc there's no point in doing the UNION. So if you really want to get exactly those rows, one way to do it is in two commands. First, use a SELECT to find the value of cmc that you want to use. Then use that value for cmc in the second command. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users