From the course: CompTIA Data+ (DA0-002) Cert Prep
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Nested queries
From the course: CompTIA Data+ (DA0-002) Cert Prep
Nested queries
- [Instructor] A nested query, also known as a subquery embeds one SQL query inside of another. The inside query gets executed first, and then the results of that query are used in the outer query. For example, imagine that you wanted to know which of your employees had more than average vacation hours saved up. Well, to answer that question, first we need to know what the average number of vacation hours is among our employees, and hopefully you already have a good idea of how to do that. We can select the average vacation hours from human resources.employee. When we run that, we find that the average number is 50, so the average employee has 50 vacation hours. But what if we wanted a list of those employees? I could write another query. Let's write select business entity ID and vacation hours from Humanresources.employee, where vacation hours is greater than 50. And when I run that query, it gives me the list of 147 employees, and that is about half of the 290 employees that we…
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Structured query language3m 41s
-
SELECT statement2m 27s
-
(Locked)
Sorting results4m 3s
-
(Locked)
Filtering data4m 1s
-
(Locked)
NULL values3m 26s
-
(Locked)
Aggregating data3m 8s
-
(Locked)
Grouping data3m 7s
-
(Locked)
String manipulation2m 43s
-
(Locked)
Working with dates2m 14s
-
(Locked)
Derived values3m 16s
-
(Locked)
Set operations5m 37s
-
(Locked)
Join operations1m 58s
-
(Locked)
Inner joins7m 7s
-
(Locked)
Joining multiple tables6m 34s
-
(Locked)
Outer joins2m 55s
-
(Locked)
Nested queries2m 17s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-