CORRESPONDING is an optional clause defined by the SQL standard that changes how set operators (UNION, INTERSECT, EXCEPT) pair columns from their left and right subqueries. Without the clause, columns are matched purely by position and both subqueries must return the same number of columns with compatible data types. When CORRESPONDING is specified, only columns that share identical names in both subqueries participate in the set operation. All other columns are ignored. An extended form, CORRESPONDING BY (column1, column2 …), restricts the match to an explicit subset of common column names and discards the rest. Key behaviors:- Available with UNION [ALL], INTERSECT, and EXCEPT.- Result columns appear once for each matched name, in the order they are listed in BY, or, if BY is omitted, in the order they appear in the first subquery.- Duplicate column names that resolve to different data types raise an error.- Cannot be used as a standalone statement; it is part of a set operator.- Not widely implemented outside of a few standards-compliant engines (for example IBM Db2, Teradata, DuckDB, and Firebird).
BY
(column_list) - list - Optional. Explicit list of common column names to include in the operation. All names must exist in both subqueries.SQL:1999
It aligns columns by identical names, letting you combine result sets even when column orders differ or when extra columns exist in either subquery.
Plain CORRESPONDING matches all column names that appear in both subqueries. CORRESPONDING BY lets you specify exactly which common columns to include, ignoring the rest.
No. CORRESPONDING is only defined for set operators (UNION, INTERSECT, EXCEPT) in the SQL standard.
The database attempts to find a common supertype. If it cannot, the statement raises a type mismatch error.