Skip to main content
← PL/SQL Topics

SQL Integration

Explain scalar and correlated subqueries in Oracle SQL

Scalar & Correlated Subqueries

ExplanationOracle Fusion / EBS · Technical · PL/SQLHigh confidenceGenerated

A scalar subquery returns one value; a correlated subquery references a column from the outer query.

How it works

A scalar subquery returns exactly one column and at most one row, so it can be used anywhere a single expression is valid — a SELECT-list column, a WHERE comparison. A correlated subquery references a column from the outer query in its own WHERE clause, so it conceptually re-evaluates once per outer row rather than running independently once — the mechanism behind EXISTS-based filtering and per-row scalar lookups.

How it works
SELECT
  e.last_name,
  e.salary,
  (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id) AS dept_avg_salary
FROM employees e
WHERE EXISTS (
  SELECT 1 FROM employees e2
  WHERE e2.department_id = e.department_id AND e2.salary > e.salary
);

Related questions

GroundingGenerated

Model-generated, grounded against the curated knowledge layer. Check specifics against your instance.

Have a follow-up, or a different question?

Continue in Ask Oracle AI