Invalid table alias or column reference b
Try doing this:
SELECT count(*) as TotalCount, b.region_codefrom XXX a INNER JOIN YYY b ON a.ui = b.uidwhere a.dt = '2015-04-15'group by b.region_codeorder by region_code
The problem with your code is that
b.region_code doesn't exist after the
order by. The alias exists (
region_code) because that is in the
select. The qualified alias does not, because the
b is no longer valid after the
group by. I think you could write:
order by max(b.region_code)
But that would be silly in this case.
Note that this is common to all databases, except MySQL.