From the course: Advanced SQL for Application Development
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Avoiding N+1 queries
From the course: Advanced SQL for Application Development
Avoiding N+1 queries
- Now starting again from where we left off, one of the things we often have to do, is look up data from more than one table. Now there are a couple of different ways of doing that. Now a common way, that people who are maybe new to SQL will do, is to fetch information from one table, save that information in a variable, loop over it, and then go get information from the second table. Let's see how that would work using our all ovens. So suppose we have our list of all ovens and now let's say we want to get information from product orders, to see what orders include ovens. One way to do that, is to essentially just loop over the, all the items in all ovens. So let's see how that would look. First of all, I'm going to create a cursor conn.cursor and I'm going to have a local variable here called fetch, all count, which I'm going to use just to print out, to show how many times we're going to the database. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Designing an ecommerce application database6m 5s
-
(Locked)
Creating tables and loading data4m 12s
-
(Locked)
Using environment variables for connection parameters3m 57s
-
Connecting to a database2m 28s
-
(Locked)
Parameterizing SELECT statements3m 37s
-
(Locked)
Avoiding N+1 queries7m 18s
-
(Locked)
Challenge: Write a parameterized query in Python43s
-
(Locked)
Solution: How to write a parameterized query in Python2m 21s
-
(Locked)
-
-
-
-
-
-