一个查询依赖另一个查询
初始化数据: -- 用户表(user) create table `user` ( `id` int auto_increment primary key, `username` varchar(50) -- 用户姓名 ); -- 订单表(orders) create table `orders` ( `id` int auto_increment primary key, `price` double, `user_id` int ); -- 给订单表添加外键约束 alter table orders add constraint user_fk foreign key (user_id) references user(id); -- 向user表中添加数据 insert into user values(3,‘张三‘); insert into user values(4,‘李四‘); insert into user values(5,‘王五‘); insert into user values(6,‘赵六‘); -- 向orders 表中插入数据 insert into orders values(1,1314,3); insert into orders values(2,1314,3); insert into orders values(3,15,4); insert into orders values(4,315,5); insert into orders values(5,1014,null);
原文:https://www.cnblogs.com/yisennnn/p/13373823.html