What is subquery in Oracle with example?
Table of Contents
Oracle subquery is a SELECT statement that is written inside another statement or query (We can say it a nested query or a query which is present within a query) which can be SELECT, INSERT, UPDATE or even DELETE statement and generally, these sub-queries reside inside the WHERE clause, the FROM clause or the SELECT …
How does subquery work in Oracle?
Essentially, a subquery in a select gets a scalar value and passes it to the main query. A subquery in select is not allowed to pass more than one row and more than one column, which is a restriction. Here, we are passing a count to the main query, which, as we know, would always be only a number- a scalar value.
Can we use functions in subqueries?

The trick to placing a subquery in the select clause is that the subquery must return a single value. This is why an aggregate function such as the SUM, COUNT, MIN, or MAX function is commonly used in the subquery.
What is an example of a subquery?
A subquery can be used anywhere an expression can be used in the SELECT clause. The following example finds the salaries of all employees, their average salary, and the difference between the salary of each employee and the average salary.
What is subquery and types?
Type of Subqueries Single row subquery : Returns zero or one row. Multiple row subquery : Returns one or more rows. Multiple column subqueries : Returns one or more columns. Correlated subqueries : Reference one or more columns in the outer SQL statement.

How many types of subqueries are there in Oracle?
There are three broad types of a subquery in SQL. This chapter from OCA Oracle Database 11g: SQL Fundamentals I Exam Guide explains differences between a single-row subquery, multiple-row subquery and correlated subquery .
How many subqueries can be written in Oracle?
A subquery in the WHERE clause of a SELECT statement is also called a nested subquery. A subquery can contain another subquery. Oracle Database imposes no limit on the number of subquery levels in the FROM clause of the top-level query. You can nest up to 255 levels of subqueries in the WHERE clause.
How correlated subquery works in Oracle with example?
Introduction to the Oracle correlated subquery First, you can execute the subquery independently. Second, Oracle evaluates the subquery only once. Third, after the subquery returns a result set, the outer query makes use of them. In other words, the outer query depends on the subquery.
How many types of subquery are there?
There are three broad divisions of subquery: Single-row subqueries. Multiple-row subqueries. Correlated subqueries.