Insert into a table selecting data from a sub query I would like to insert a few data into a table selecting data from a subquery having multiple joins.

I tried the following way:

insert into mytable (columns) 
select * from 
 (select columns 
  from tableA 
  UNION ALL 
  select columns from tableB 
  UNION ALL 
  select columns from tableC)


Can you please suggest me a way out, since I am getting the following error while executing the above query.


  Incorrect syntax near ')'.
Add some alias:

insert into mytable (columns) 
select t.* from (
    select columns from tableA 
    UNION ALL
    select columns from tableB
    UNION ALL
    select columns from tableC
) t