当前位置:网站首页>One to many association in MySQL to obtain the latest data in multiple tables
One to many association in MySQL to obtain the latest data in multiple tables
2022-06-27 22:39:00 【Meow meow more】
background
stay msyql One to many queries often appear in queries , Only query the latest data in one of the multiple tables or the data that meets a certain condition . If only GROUP BY The query results cannot be satisfied , At this point, the query becomes complex .
for instance , School watch 、 The curriculum 、 Course sequencing table , I need the top course in each school .
In some cases, we can see that the method used by people is :
``SELECT c.Id FROMt_course_rank AS ocrLEFT JOIN ( SELECT * FROM t_course WHERE coursetype = 2 ORDER BY Visit DESC ) AS c ON c.Id = ocr.courseidLEFT JOIN t_school AS s ON c.LoginId = s.LoginIdWHEREc.LoginId IN (19) GROUP BY c.LoginId
Complete the latest data in a condition through temporary table Association , But this kind of query is not accurate , Can't meet the conditions .
Solution
1. Find out all the data first , Then traverse to query (php in foreach Query in ), Simple , But it's inefficient , Process can be complex .
2. Sort first and then call
边栏推荐
- Figure countdownlatch and cyclicbarrier based on AQS queue
- CDH集群之YARN性能调优
- Infiltration learning - problems encountered during SQL injection - explanation of sort=left (version(), 1) - understanding of order by followed by string
- go语言切片Slice和数组Array对比panic: runtime error: index out of range问题解决
- The "business and Application Security Development Forum" held by the ICT Institute was re recognized for the security capability of Tianyi cloud
- Flask application case
- The problem of minimum modification cost in two-dimensional array [conversion question + shortest path] (dijkstra+01bfs)
- Login credentials (cookie+session and token token)
- How to do function test well? Are you sure you don't want to know?
- 7 jours d'apprentissage de la programmation simultanée go 7 jours de programmation simultanée go Language Atomic Atomic Atomic actual Operation contains ABA Problems
猜你喜欢

YOLOv6:又快又准的目标检测框架开源啦
![[microservices] (16) -- distributed transaction Seata](/img/1b/aeb534d5a0bd40f5fc14e64bdf5aa9.png)
[microservices] (16) -- distributed transaction Seata

Crawler notes (2) - parse

CUDA error:out of memory caused by insufficient video memory of 6G graphics card

Go from introduction to practice -- shared memory concurrency mechanism (notes)

《7天學會Go並發編程》第7天 go語言並發編程Atomic原子實戰操作含ABA問題

管理系統-ITclub(下)

Infiltration learning - problems encountered during SQL injection - explanation of sort=left (version(), 1) - understanding of order by followed by string

对话乔心昱:用户是魏牌的产品经理,零焦虑定义豪华

01 golang environment construction
随机推荐
九九乘法表——C语言
Exclusive interview with millions of annual salary. What should developers do if they don't fix bugs?
Is it safe to open a stock account through the account opening link given by the CICC securities manager? I want to open an account
Yolov6: the fast and accurate target detection framework is open source
Is flush stock trading software reliable?? Is it safe?
Basic knowledge of loop traversal and function
哈希表-数组之和
This set of steps for performance testing using JMeter includes two salary increases and one promotion
初识C语言 第二弹
Acwing week 57 longest continuous subsequence - (binary or tree array)
Yarn performance tuning of CDH cluster
Vue+mysql login registration case
OpenSSL programming I: basic concepts
正则表达式
[MySQL practice] query statement demonstration
average-population-of-each-continent
Oracle obtains the beginning and end of the month time, and obtains the beginning and end of the previous month time
Codeforces Round #721 (Div. 2)
PCIe knowledge point -008: structure of PCIe switch
PHP连接数据库实现用户注册登录功能