From the course: MySQL Advanced Topics (2019)
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Searching within a result set - MySQL Tutorial
From the course: MySQL Advanced Topics (2019)
Searching within a result set
In this lesson, I'll show you a practical example of using sub select to provide a list of rows to search for in a table. So here we're using the album database, and I have a simple select statement where I get the album I.D. from the track table where the tracks have a duration of less than 90 seconds. So any album that has any tracks that are less than 90 seconds I'll get the album I.D. and I'm using select distinct so I only get one row per result. Even if there's more than one track that's shorter than 90 seconds in that album. So I'm going to go ahead and execute this. You see that we get two album I.D.s. So these are the two albums in this database that have tracks where the duration is less than 90 seconds. Now I can use this as a sub select, I don't need the use album anymore. So I can say select, asterisk, from album. And I can say where I.D. in. And then put this select inside parentheses. And this will…
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.