Mysql exists用法小结
# 查询体重秤
select * from activity_main where act_code in (
select act_code from activity_sku where sku = '翎野君的体脂称'
)
# 查询体重秤
select * from activity_main a where exists (
select 1 from activity_sku b where a.act_code = b.act_code and b.sku = '翎野君的体脂称'
)
# 模糊查询B-BEKO英国婴儿推车
select * from activity_main where act_code in (
select act_code from activity_sku where sku like '%B-BEKO%'
)
# 模糊查询B-BEKO英国婴儿推车
select * from activity_main a where exists (
select 1 from activity_sku b where a.act_code = b.act_code and b.sku like '%B-BEKO%'
)
# 查询在博客园举办的活动
select * from activity_main where act_code in (
select act_code from activity_area where area = '博客园'
)
# 查询在博客园举办的活动
select * from activity_main a where exists (
select 1 from activity_area b where a.act_code = b.act_code and b.area = '博客园'
)
# 在博客园举办活动且活动奖品为华为手机的活动信息
select * from activity_main where act_code in (
select act_code from activity_area where area = '博客园' and act_code in (
select act_code from activity_sku where sku = '华为P30Pro'
))
# 内层的exists语句只在当前where语句中生效,最终是否返回,要根据最外层的exists判断,如果是 true(真)就返回到结果集,为 false(假)丢弃。
select * from activity_main a where exists (
select 1 from activity_area b where a.act_code = b.act_code and b.area = '博客园' and exists
(select 1 from activity_sku c where a.act_code = c.act_code and c.sku = '华为P30Pro')
)
相关文章
- SQLyog连接MySQL8.0+报错:错误号码2058的解决方案
- 深入分析MySQL数据类型 DECIMAL
- CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)运行环境步骤
- Ubuntu系统安装mysql超详细步骤
- 在VB.NET应用中使用MySQL的方法
- C++连接mysql数据库(改进版)
- Apache+PHP+MySQL搭建PHP开发环境图文教程
- 一文详解MySQL 存储引擎
- 解决远程连接MySQL报错:2003 - Can‘t connect to MySQL server on ‘X.X.X.X‘ (10060 “Unknown error“)问题
- APMServ一键快速搭建Apache+PHP+MySQL+Nginx+Memcached+ASP运行平台教程