The where clause is evaluated before the select clause, so you cannot reference the selection of aliases in the where clause.
However, you can refer to aliases from the view.
select * from ( select user as u1, url as u2 from rank_test ) t1 where u1 <> ""; select * from ( select user, count(*) as cnt from rank_test group by user ) t1 where cnt >= 2;
Side note: a more efficient way to write the last request would be
select user, count(*) as cnt from rank_test group by user having count(*) >= 2
If I remember correctly, you can refer to the alias in having ie having cnt >= 2
Fuzzytree
source share