当前位置:网站首页>MySQL takes the union of two query conditions and then queries
MySQL takes the union of two query conditions and then queries
2022-07-19 04:55:00 【Xiaoxinai programming】
Catalog
Problem analysis :
such sql It sounds a little complicated , But when you think about it carefully, it's actually a very simple sql, First find out what you need sqlselect dept_id from sys_dept sd where AREACODETYPE ='4' and AREACODE ='1111'
And then we sql The first condition is found , And put this sql Continue to query as a condition
select role_id from sys_role_dept srd,
(select dept_id from sys_dept sd where AREACODETYPE ='4' and AREACODE ='1111') a
where srd.dept_id = a.dept_id

Then you can continue the association query
select user_id from sys_user_role sur,(select role_id from sys_role_dept srd,
(select dept_id from sys_dept sd where AREACODETYPE ='4' and AREACODE ='1111') a
where srd.dept_id = a.dept_id) b where sur.role_id = b.role_id

Then the first result came out , Then we check the second result
Similar to the above logic , Finally, I won't explain the code block
select user_id from sys_user_dept sud,
(select dept_id from sys_dept sd where AREACODETYPE ='4' and AREACODE ='1111') a
where sud.dept_id = a.dept_id

Problem solving
Then the results of the first column and the second column are different , But there are similarities , Then at this time, we can carry out union value .
select a.user_id as dept_id from (select user_id from sys_user_role sur,(select role_id from sys_role_dept srd,
(select dept_id from sys_dept sd where AREACODETYPE ='4' and AREACODE ='1111') a
where srd.dept_id = a.dept_id) b where sur.role_id = b.role_id) a,(select user_id from sys_user_dept sud,
(select dept_id from sys_dept sd where AREACODETYPE ='4' and AREACODE ='1111') a
where sud.dept_id = a.dept_id)b where a.user_id = b.user_id

summary
The main thing is to use mysql Find out the data , Then treat the data as a new table file , And then we're working on it , Treat the data as another table file , But there are better ways to deal with it , I didn't write it here , You can provide some ideas ,
left join finger :
select * from a left join b on a.aid = b.bid
Take it out first a All data in the table , Then add and a,b Matching data
What is taken out at this time is :
1 a1 b1
2 a2 b2
3 a3 Null character
The result set of the left out join includes LEFT OUTER All rows of the left table specified in Clause , Not just the rows that the join columns match . If a row in the left table does not match a row in the right table , All selection list columns in the right table in the associated result set row are null .
边栏推荐
- Embrace declarative UI
- 根据日期重新排列数据js
- Introduction to redis
- Using circular statements to make login programs
- Money making master applet [latest version 5.9.9] mall / instant withdrawal of commission / distribution promotion / phone recharge / is meituan hungry for takeout
- Warriors of the Visual Studio, Assemble! (Visual Studio的勇士们,汇编吧!) 原创 2009年07月12日 19:40:00 标签:汇编 /mic
- 赚钱大师小程序【最新版5.9.9】商城/佣金即时提现/分销推广/话费充值/美团饿了么外卖
- mysql主从架构和读写分离、以及高可用架构
- 类对象自动注入属性操作工具
- Demo analysis of sliding conflict external interception method
猜你喜欢
![[vuforia] simple logic of image recognition](/img/c4/c3640fd37ec75d89da367d310b10a6.png)
[vuforia] simple logic of image recognition

2022最新版校园跑腿小程序源码

Notes on Advanced Mathematics: selected exercises of Wu Yue

MYSQL两个查询条件取并集然后进行查询

TiDB 性能分析和优化

Load balancer ribbon practice

Basic operations of index library operation

Tidb performance analysis and optimization

ThreadLocal线程安全示例及其原理

DirectExchange交换机的简单使用。
随机推荐
知识图谱de构建与应用(六):知识图谱的存储、服务与质量
Expected to replace deepfake? Uncover this year's super popular nerf Technology
使用循环语句制作登录程序
PingCAP Clinic 数据采集说明
masm32写程序
Project team summer vacation summary 02
Kubernetes 的监控与告警
Mysql8.026-- view (bottom)
UE plug-in electronicnodes 5.0.0/4.23-4.27
EMQX 压力测试踩得坑供大家参考
一文带你了解HAProxy
服务端接口测试-接口测试的测试点【杭州多测师】【杭州多测师_王sir】
Redis cluster interview questions
[FPGA tutorial case 26] realize the basic operation of decimals through Verilog in FPGA
Notes on Advanced Mathematics: a conjecture about the Equivalent Infinitesimal Substitution
Embrace declarative UI
畢設:基於Vue+Socket+Redis的分布式高並發防疫健康管理系統
Simple UI funny text conversion Emoji expression wechat applet supports sentence word conversion_ Source code
Exploration: pharmaceutical factory system network clock synchronization (NTP time synchronization server)
网址在线封装APK系统源码