From the course: Oracle Database 12c: Basic SQL

Unlock the full course today

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

Subqueries

Subqueries - Oracle Database Tutorial

From the course: Oracle Database 12c: Basic SQL

Start my 1-month free trial

Subqueries

- [Instructor] Subqueries in the SQL language are ways for us to nest multiple SQL commands inside a single SQL query. Sounds complex? It's actually quite straightforward. Let's see a simple example in action. We'll start by selecting all of the departments we have in our departments table. So select, star, from departments. We can see that Department number 20 is our Marketing department. Remember that as we'll use these values in a moment. Now, let's assume we want to write a SQL query which returns all of the employees in our employees table which are assigned to the Marketing department. One way for us to do that is to type select, star, from employees, where department ID equals 20 because 20 is the Department ID code. This query will run as expected. However, there's another slightly cooler way to accomplish the same thing. Instead of typing department ID equals 20 and specifying the actual department ID itself, I can also type, where department ID equals, and then inside…

Contents