From the course: Oracle Database 12c: Advanced SQL

Unlock the full course today

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

Using single-value subqueries

Using single-value subqueries - Oracle Database Tutorial

From the course: Oracle Database 12c: Advanced SQL

Start my 1-month free trial

Using single-value subqueries

- [Instructor] As we saw in our previous video subqueries allows you to write SQL queries that select data, for a criteria, that is developed during query run-time, that is as the query itself is executing. For example, we can use a subquery in the WHERE clause of another sequel query. Instead of having to explicitly specify the values we wish to filter on. A subquery can be executed, testing these values to the external or encompassing query. Let's start with a simple example. Selecting the details for the employee earning the highest salary in our company. So I'll type select max salary from employees. We can now use this query as a subquery in another query. So I'll type select star, from employees, where salary equals, and then instead of specifying a literal string, inside parenthesis I can just contain my subquery. So what will happen is that the Oracle database will first execute the subquery, return the result of the subquery, which is $24,000, and then this value will…

Contents