On 9 Jun 2009, at 11:18am, Martin Engelschalk wrote: > the column name in the order by - clause "name" has to match one of > the > columns of the select statement, because it is a union. > Your columns are "id", "url" ad "selected", none of which is "name". > > Obviously, your table does contain a column named "name", but > because of > the union this can not be used. The order by is executed after the > union > of the two result sets, and the column "name" ist not part of the > result > set. > > Use the following: > > SELECT id, url, selected, name FROM db1.test UNION > SELECT id, url, selected, name FROM db2.test > ORDER BY name ASC, id DESC LIMIT 100"
I would add to Marin's answer that reading the above, I have no idea which database the column 'name' is in. Suppose db1 and db2 both had a 'name' column. Which one would it be. So it might be better to use SELECT id, url, selected, name FROM db1.test UNION SELECT id, url, selected, name FROM db2.test ORDER BY db1.name ASC, db2.id DESC LIMIT 100 _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users