Correlated Subquery Examples | SQL SELECT Statements | Teradata Vantage - Example: Combining Equality and Inequality Conditions in a Correlated Subquery - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantageā„¢

You can use correlated subqueries to specify a combination of equality and inequality constraints with the subquery.

For example, to select the names of all students who are younger than all students at the same grade, you can perform the following query:

     SELECT name
     FROM student st1
     WHERE age < ALL (SELECT age
                      FROM student st2
                      WHERE st1.grade = st2.grade
                      AND st1.stno <> st2.stno);