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.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
vjt1596846980081.ditamap
dita:ditavalPath
vjt1596846980081.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);