当前位置:网站首页>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
边栏推荐
- The "business and Application Security Development Forum" held by the ICT Institute was re recognized for the security capability of Tianyi cloud
- \W and [a-za-z0-9_], \Are D and [0-9] equivalent?
- 结构化机器学习项目(一)- 机器学习策略
- Go from introduction to practice -- definition and implementation of behavior (notes)
- 01 golang environment construction
- Experience sharing of meituan 20K Software Test Engineers
- PHP连接数据库实现用户注册登录功能
- YOLOv6:又快又准的目标检测框架开源啦
- Codeforces Round #719 (Div. 3)
- 使用sqlite3语句后出现省略号 ... 的解决方法
猜你喜欢

从学生到工程师的蜕变之路

爬虫笔记(1)- urllib

Figure countdownlatch and cyclicbarrier based on AQS queue

Deep learning has a new pit! The University of Sydney proposed a new cross modal task, using text to guide image matting

爬虫笔记(3)-selenium和requests

Crontab scheduled task common commands

Management system itclub (Part 1)

How to participate in openharmony code contribution

Exclusive interview with millions of annual salary. What should developers do if they don't fix bugs?

Ellipsis after SQLite3 statement Solutions for
随机推荐
go语言切片Slice和数组Array对比panic: runtime error: index out of range问题解决
北京邮电大学|用于成本和延迟敏感的虚拟网络功能放置和路由的多智能体深度强化学习
清华大学教授:软件测试已经走入一个误区——“非代码不可”
Use logrotate to automatically cut the website logs of the pagoda
Go from introduction to practice -- definition and implementation of behavior (notes)
Which method is called for OSS upload
使用Jmeter进行性能测试的这套步骤,涨薪2次,升职一次
DCC888 :Register Allocation
Golang uses regularity to match substring functions
Crawler notes (1) - urllib
Crawler notes (2) - parse
信通院举办“业务与应用安全发展论坛” 天翼云安全能力再获认可
改善深层神经网络:超参数调试、正则化以及优化(三)- 超参数调试、Batch正则化和程序框架
微服务之服务网关
Fill in the blank of rich text test
xpath
Learn to go concurrent programming in 7 days go language sync Application and implementation of cond
Where can I set the slides on the front page of CMS applet?
Basic data type and complex data type
对话乔心昱:用户是魏牌的产品经理,零焦虑定义豪华