From the course: Learning SQL Programming

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Compound Select

Compound Select - SQL Tutorial

From the course: Learning SQL Programming

Start my 1-month free trial

Compound Select

- [Instructor] Sometimes we need to use more than one select statement to get the information we want. It's often the case that we want to set up a query that relies on the result of another query. Using a secondary select statement inside of another query is called a sub-query or sub-select, and it helps us to narrow down or zero in on a specific set of data to use in that larger query. Let's get a listing of all the people in our database who achieved the highest score on our quiz. It might occur to us to write select first_name, last_name, quiz_points, from people where quiz_points equals max quiz_points. But when I run that, I have an error. Misuse of aggregate function max. This max function, like the other aggregate functions, min, average, and so on, won't work this way as part of a where condition. So instead of just max here, I'll wrap it inside a select statement inside of parentheses. So my where condition becomes where quiz_points equals select max quiz_points from people.…

Contents