A * by itself must come first, so
SELECT *, "A" AS SortCode FROM Jobs
> I am not sure about MySQL but in Oracle this will NOT work: "SELECT "A" AS SortCode,
> * FROM Jobs"
> However, this WILL: "SELECT "A" AS SortCode,
> Jobs.* FROM Jobs"
> Try adding the table or alias in front of the "*".
This works in MySQL, as well.
> In general, however, I will repeat my suggestion from before - try to do
> everything in one pass - it's much more efficient.
> Something like this:
> "SELECT (CASE
> WHEN Jobs.Project = MyProject AND Jobs.JobType = MyJobType then "A"
> WHEN Jobs.Project => MyProject AND Jobs.JobType <> MyJobType
> then "B"
> WHEN Jobs.Project <> MyProject AND Jobs.JobType = MyJobType
> then "C"
> WHEN Jobs.Project <> MyProject AND Jobs.JobType <>
> MyJobType then "D"
> END CASE
> ) SortCode,
> ORDER BY SortCode ASC,
> Jobs.Priority ASC
> You might have to tinker with the syntax if CASE is not available in
> MySQL to this extent but that's the general idea.
MySQL has CASE, with almost the same syntax you describe, except it ends
with END rather than END CASE. See