Description:
output:
=======
mysql> drop table if exists t1; create table t1(c1 int, c2 int);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into t1 values(1,2),(2,1);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select exists( select * from t1 order by 2);
ERROR 1054 (42S22): Unknown column '2' in 'order clause'
mysql> select * from t1 order by 2;
+------+------+
| c1 | c2 |
+------+------+
| 2 | 1 |
| 1 | 2 |
+------+------+
2 rows in set (0.00 sec)
mysql> select version();
+------------+
| version() |
+------------+
| 5.6.22-log |
+------------+
1 row in set (0.00 sec)
Problem:
========
In "select * from t1 order by 2", the clause "order by 1" is processed successfully.
But in the subquery "select exists( select * from t1 order by 2)", it tells "1054 (42S22): Unknown column '2' in 'order clause'".
Since the first one succeeds, the subquery is expected to be successful.
How to repeat:
drop table if exists t1; create table t1(c1 int, c2 int);
insert into t1 values(1,2),(2,1);
select exists( select * from t1 order by 2);
select * from t1 order by 2;
Suggested fix:
The following SQL succeeds:
select exists( select * from t1 order by 2)