You can avoid many n+1 issues by using lateral joins in MySQL

You can avoid many n+1 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.com/for-each-loop-lateral-join

We're writing a book, you can get it for free here.