From the course: From Excel to SQL

Unlock the full course today

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

Subqueries in SQL

Subqueries in SQL

From the course: From Excel to SQL

Start my 1-month free trial

Subqueries in SQL

- Let's say, you want to zero in on some specific information from your dataset. For example, maybe you want to find the employee that has taken the most vacation days in your company. So how can we do that? What should our SQL statement look like? Let's head over to DB Browser and see what we might do. Now, a pretty logical place to start is by selecting all the employees and ordering them by vacation days. So let's start with SELECT * FROM Employees, order by vacation taken, and then run the query. Okay, you can see here we're looking at the employee who's taken the least amount of vacation days, and that's Gilly. We'll need to flip this around. So let's return the results in descending order by using the descending keyword. And we do that by adding DESC to the ORDER BY. After we made that change, we can rerun the query. And now we see that Basil has taken the most vacation days within the company. So we were…

Contents