1
0
Fork 0
mirror of https://github.com/archtechx/laravel-tips.git synced 2025-12-12 13:24:03 +00:00
laravel-tips/content/tips/you-can-avoid-many-n1-issues-by-using-lateral-joins-in-mysql.md
Samuel Štancl e42fd0da62 Week 21/2022
2022-05-27 21:23:30 +02:00

644 B
Raw Blame History

title tweet_id thread_slug author_username images created_at slug
You can avoid many n+1 issues by using lateral joins in MySQL 1530215268915417089 weekly-thread-2022-21 tobias_petry
https://pbs.twimg.com/media/FTmHagcX0AEBn_k.jpg
2022-05-27T15:52:04+00:00 you-can-avoid-many-n1-issues-by-using-lateral-joins-in-mysql

Database Tip

Sometimes you want to get e.g. the last three orders for every customer. Normal joins can't do that. You have to execute n+1 queries in code, which is slow!

But with lateral joins, you can do one for-each loop join in SQL 🤯 https://sqlfordevs.io/for-each-loop-lateral-join