为什么这个结果在子查询中使用父表的列

时间:2017-07-31 08:55:43

标签: mysql subquery

@Output()

表格中的数据

create table teacher (
        id int,
        name varchar(126),
        primary key(id)
)DEFAULT CHARSET=utf8 ENGINE=InnoDB;

create table class (
        id int,
        name varchar(126),
        t_id int,
        primary key(id),
        foreign key (t_id) references  teacher(id)  on delete cascade on update cascade
)DEFAULT CHARSET=utf8 ENGINE=InnoDB;

sql我执行

mysql> select * from teacher ;
+----+------+
| id | name |
+----+------+
|  1 | yang |
|  2 | yan  |
+----+------+
2 rows in set (0.00 sec)

mysql> select * from  class ;
+----+---------+------+
| id | name    | t_id |
+----+---------+------+
|  1 | math    |    1 |
|  2 | english |    2 |
+----+---------+------+
2 rows in set (0.00 sec)

如何执行此sql并在subsql中解析t_id;

ps:这个sql不是我想要的,一个bug,但是想知道这是如何在mysql中运行的。

0 个答案:

没有答案
相关问题