子查询

子查询在()中写sql语句

 

 

 

1.单列子查询

查询一列中的一个值。

  select  * from  table  

where  列1 = (select  列1 from  table  where  列3 = 值)

and 列2=(select  列2  from  table where  列3 = 值 

 


2.单行子查询

查询出多列

  

select  t1.列1,t2.列2,t3.列3  from  table1  t1, (select 列2 from table t2 group by 列2) ,table3  t3

 

where   t1.列5=t2.列5 and t2.列4=t3.列6;

 

 

3.多行子查询

查询多条记录数据

 

in   主查询语句结果在子查询语句

  select * from table  where  列1 in (select max(列1)  from table  group by 列2 );

any

  select * from table  where  列1 = any (select max(列1)  from table  group by 列2 );

all  主查询语句的结果大于或小于子查询语句的结果

select * from table  where  列1 = any (select max(列1)  from table  group by 列2 );

 

 

  

 

转载于:https://www.cnblogs.com/topzhangRX/p/10111655.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值