Have you failed a job interview?
Send us your job interview questions and get correct answers.

Can you use different column names for tables merged using UNION ALL? What will be the column names in the result?

Experience Level: Medior
Tags: DatabasesSQL



You can use different column names. The 2 datasets are merged by a column index. The data types of the columns on the same column index must match, the names can be however different.

The result merged dataset will use the column names of the first dataset.


SELECT 1 ClientId, 'Peter' ClientName
SELECT 2 SomeClientId, 'Jill' Client

-- The output will be the following:

ClientId ClientName
1 Peter
2 Jill



No Comments Yet.
Be the first to tell us what you think.