pingcap / pingcap/tidb

The behavior of alias usage in SELECT statements is inconsistent with MySQL

Open
#61,035 0 comments 0 reactions 0 assignees View on GitHub
severity/moderate sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)
```
drop table chqin ;
create table chqin(id int);

insert into chqin values(1);

select id,(select id from chqin) as id_new, sum(id)-(select id_new) as id2 from chqin group by id;

```

### 2. What did you expect to see? (Required)
results from mysql:
```
MySQL [chqin]> select id,(select id from chqin) as id_new, sum(id)-(select id_new) as id2 from chqin group by id;
+------+--------+------+
| id | id_new | id2 |
+------+--------+------+
| 1 | 1 | 0 |
+------+--------+------+
1 row in set (0.00 sec)
```

### 3. What did you see instead (Required)
results from tidb:
```
MySQL [test1]> select id,(select id from chqin) as id_new, sum(id)-(select id_new) as id2 from chqin group by id;
ERROR 1054 (42S22): Unknown column 'id_new' in 'field list'
```

### 4. What is your TiDB version? (Required)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.