当前位置:网站首页>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 .
边栏推荐
- [FPGA tutorial case 26] realize the basic operation of decimals through Verilog in FPGA
- CKS 核心知识点概述
- Mysql8.026-- view (bottom)
- [论文精读]BERT
- Database and the future of open source
- itext修改pdf文字
- Blessing for the elderly popular short video wechat applet source code download support traffic master
- Some concepts of ES
- shardingsphere的核心概念和快速实战
- 三种高并发方式实现i++
猜你喜欢

shardingproxy分库分表实战及同类产品对比
![[vuforia] simple logic of image recognition](/img/c4/c3640fd37ec75d89da367d310b10a6.png)
[vuforia] simple logic of image recognition

Database learning notes (I) retrieval data

ThreadLocal线程安全示例及其原理

Simple UI funny text conversion Emoji expression wechat applet supports sentence word conversion_ Source code

UE-插件 ElectronicNodes 5.0.0/4.23-4.27

es的一些概念

一文了解配置中心

Hightec new aurix tc37x demo project

UE plug-in electronicnodes 5.0.0/4.23-4.27
随机推荐
Expected to replace deepfake? Uncover this year's super popular nerf Technology
[vuforia] simple logic of image recognition
mysql主从架构和读写分离、以及高可用架构
JS中substr与substring的区别
redis 安装
Common PostgreSQL data operation notes (updated from time to time)
有望取代Deepfake?揭秘今年超火的NeRF技
Notes on Advanced Mathematics: selected exercises of Wu Yue
Differences between substr and substring in JS
老年祝福火爆短视频微信小程序源码下载支持流量主
DSL搜索结果处理,包括排序,分页,高亮
Construction and application of knowledge atlas de (V): knowledge reasoning
数据库取配置文件字段,然后进行数据处理和判断
tidb 学习
知识图谱de构建与应用(七):大规模知识图谱预训练
npm安装教程
Some concepts of ES
[论文精读]BERT
itext修改pdf文字
面临的挑战和优势,并预测NeRF最终将取代Deepfake