I have a simple query:
SELECT u_name AS user_name FROM users WHERE user_name = "john";
I get Unknown Column 'user_name' in where clause
. Can I not refer to 'user_name'
in other parts of the statement even after select 'u_name as user_name'
?
try your task using IN condition or OR condition and also this query is working on spark-1.6.x
or
Think of it like this, your where clause evaluates first, to determine which rows (or joined rows) need to be returned. Once the where clause is executed, the select clause runs for it.
To put it a better way, imagine this:
You can't reference the first half without the second. Where always gets evaluated first, then the select clause.
Either:
or:
The latter ought to be the same as the former if the RDBMS supports predicate pushing into the in-line view.
What about:
Not as far as I know in MS-SQL 2000/5. I've fallen foul of this in the past.
Your defined
alias
are not welcomed by theWHERE
clause you have to use theHAVING
clause for thisOR you can directly use the original column name with the
WHERE
Same as you have the result in user defined alias as a result of subquery or any calculation it will be accessed by the
HAVING
clause not by theWHERE