Example: Simple Subquery Using the ALL Logical Predicate - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

The following SELECT statement retrieves the employees with the highest salary and the most years of experience:

     SELECT emp_no, name, job_title, salary, yrs_exp
     FROM employee
     WHERE (salary,yrs_exp) >= ALL (SELECT salary,yrs_exp
                                    FROM employee);
The query returns this many rows … WHEN this condition evaluates to TRUE …
0 employees with the highest salary do not also have the most years experience.
1 there is only one employee with the highest salary and years experience.
multiple there is more than one employee with the highest salary and years experience.

For the current data in the employee table, the result looks like this:

     EmpNo Name      JobTitle     Salary  YrsExp
     ----- --------- --------- --------- -------
     10018 Russell S President 65,000.00      25

The result shows that one employee has both the highest salary and the most years of experience.