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

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
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);