select ..from..where..=(select ..from ..where=‘‘)子查询的用法及理解

use xie
go
select *from Table_1
select *from table_6
select *from table_4

select *from Table_1 where ok=567  --父查询
select *from Table_1 where ok=(select  ok from  table_6 where jj=78) --子查询 
 
select name from table_4 where id=(
select name from Table_1 where ok=(select  ok from  table_6 where jj=78) ) --3表子查询
/*
1、子查询必须是放在括号里面的、先执行子查询、然后再根据查询的结果为父查询的条件来查
   比如上面子查询的结果是‘567’,那父查询的条件ok=567的时候查的是什么结果、就是这样
2、子查询在‘=,<,>’前面,像这些比较运算符只允许一个列名、就是不能用select * from查全部或selct 列2,列2,列3 from多个查询
3、order by不能放在子查询后面、只能在括号之外的父查询后面
*/
select ok as 没有,go_id as 滚 
from Table_1 as a
inner join table_4 as b on a.ID=78
where a.ID=78                          --子查询的结果也可以用多表内、外连接来查、而且内外连接可以查任何字段、而子查询只能查主表内的字段

更多详细教程、请关注我的微信公众号:客兴天下

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水亦流人必上

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值