I am getting the following error while executing query in SQLite:
4th ORDER BY term does not match any column in the result set
select * from Users where deleted != 1 AND DATE(created) <= '2013-10-09' and
DATE(created) >= '2013-09-09T12:41:55.261Z' UNION select * from Users where deleted != 1 AND
owner NOT IN(Select userid from Customer)
order by Type DESC,License ASC,NUM ASC,"MCTD#" ASC,Name DESC;
If the name of your column is
MCTD%23, then you must use exactly that name to refer to the column.
% escapes are a feature of the HTTP protocol and are not used in SQL.
The reason that
"MCTD#" appears to work without
UNION is that it does not actually refer to a column. When you are not using
UNION, you can use arbitrary expressions in the
ORDER BY clause. If a quoted column name is not found, then for compatibility with MySql,
"MCTD#" is interpreted as
'MCTD#', which is just a constant string value that does not actually affect the sorting.
ORDER BY does not allow arbitrary expressions but only actual column names from the result set, so it is not possible to interpret
"MCTD#" as a string value.