-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unexpected unknown column
error
#24318
Comments
The minimal reproducible case:
|
The root cause is that in |
I tried the case: then get the error result: this issue influence the mybatis pagehelper tool , course ' select count(0)' It seems a terrible issue |
@caoyipeng2008 Hi, what's the impacted SQL in the mybatis's pagehelper tool? |
page helper tool use 'select count(0)' as the default to get the total count. but this issue make some trouble. and alse any select 'number' as column should be avoided. |
similar case as it depicted
which means scalar subquery can only refer forward-defined items in the outer select list. |
MySQL allows backward reference which may be useful in some situations. create table t1(id int, c1 int, c2 int);
create table t3(id int, c3 int);
mysql> select id+1 as foobar, (select c1 from t1 where id = foobar) from t3;
Empty set (0.00 sec)
mysql> select abs(-1)+1 as foobar, (select c1 from t1 where id = foobar) from t3;
Empty set (0.00 sec)
mysql> select count(*) as foobar, (select c1 from t1 where id = foobar) from t3;
ERROR 1247 (42S22): Reference 'foobar' not supported (reference to group function)
mysql> select count(*) as foobar, (select c1 from t1 having id = foobar) from t3;
+--------+----------------------------------------+
| foobar | (select c1 from t1 having id = foobar) |
+--------+----------------------------------------+
| 0 | NULL |
+--------+----------------------------------------+
mysql> select count(*) as foobar, (select c1 from t1 group by foobar) from t3;
ERROR 1247 (42S22): Reference 'foobar' not supported (reference to group function)
mysql> select id+1 as foobar, (select c1 from t1 group by foobar) from t3;
Empty set (1.86 sec)
mysql> select (select c1 from t1 where id = foobar), id as foobar from t3;
ERROR 1247 (42S22): Reference 'foobar' not supported (forward reference in item list)
mysql> select id as foobar, foobar as foobar1 from t3;
ERROR 1054 (42S22): Unknown column 'foobar' in 'field list'
mysql> select count(*) as foobar, (select c1 from t1 where id = foobar) from t3;
Empty set (0.00 sec)
mysql> select id+1 as foobar from t3 having (select 1 from t1 having id < foobar) < 10;
Empty set (47.81 sec)
mysql> select (select 1 from t1 having id < foobar), id+1 as foobar from t3;
ERROR 1247 (42S22): Reference 'foobar' not supported (forward reference in item list) |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
7e15333 in master
The text was updated successfully, but these errors were encountered: