get a 'Column specified multiple times' error with union all sql query

advertisements

This is my query:

select * from (
    select Name, Address
    from table1
    UNION ALL
    select Name, Address
    from table2
) D

When executing this query getting error:

The column 'Name' was specified multiple times for 'D'.


Use alias names

select * from (
    select t1.Name, t1.Address
    from table1 as t1
    UNION ALL
    select t2.Name, t2.Address
    from table2 as t2
) D