Consider a table my_table , with contents shown:
You execute:
SELECT a b, b a
FROM my_table
WHERE a < s
ORDER BY b;
What does this statement return?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Consider a table my_table , with contents shown:
You execute:
SELECT a b, b a
FROM my_table
WHERE a < s
ORDER BY b;
What does this statement return?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
D
Yes, D is correct. The reason is, you can’t use an alias in a WHERE-Clause but you can use it in the ORDER BY.
(The “s” in the WHERE clause is a “5”)
http://dev.mysql.com/doc/refman/5.6/en/problems-with-alias.html
create table my_table
(
a int,
b int
);
INSERT INTO my_table VALUES(1,6),(3,4),(5,2);
select * from my_table;
SELECT a as b,b as a
FROM my_table
WHERE a < 5 #Only affects source A (Not B as A)#
ORDER BY b;
b, a
'1', '6'
'3', '4'
D