I have a problem with the WHERE CLAUSE
in mysql query. I want to filter data from a column that I directly defined.
this is my example table (named MEMBER) :
++++++++++++++++
title | name |
++++++++++++++++
leaf | andro |
moon | sheila |
rocks | sarah |
I run this query :
SELECT *, IF( title = "moon", "fly","on earth") AS status FROM MEMBER;
and the result :
+++++++++++++++++++++++++
title | name | status |
+++++++++++++++++++++++++
leaf | andro |on earth|
moon | sheila |fly |
rocks | sarah |on earth|
But why when I added a WHERE CLAUSE
to filter the status
column at the end of the query it returns an error?
this is the query:
SELECT *, IF( title = "moon", "fly","on earth") AS status
FROM MEMBER
WHERE status = "fly";
the error message is :
#1054 - Unknown column 'status' in 'where clause'
the 'directly defined' column that i mean is status
column, it's not exist in the table but i created/defined it in the query.
I have tried to create status
column in the table and it has null value, so when i run the second query (that containing WHERE CLAUSE
), it would returns zero result
.
i know another way to filter the data, i can use this query :
SELECT *, IF( title = "moon", "fly","on earth") AS status
FROM MEMBER
WHERE title = "moon";
but I can't do the filter by using that query in my case. I have to filter the status
column.
Please don't see this question as a fool question, because this is the case that i have.
So, anybody has the alternatives?