Error Code: 1248 Alias needed in MySQL I have recently started learning MySQL and am trying to join data from two tables into a third table built.

The two tables are:

'Company Financials'   -   Column of 'Revenue'

'Fortune500'   -    Columns of 'Year' and 'Company'

My query code is:

INSERT INTO Company(ID, Year, Company, Revenue)
    (select Year, Company, Revenue
    from (select Revenue from Company_Financials
    union select Year, Company from Fortune500));

Fortune 500 Table:



Company Financials Table:



I've had multiple errors related to this code, but have been able to figure out why they were wrong.  This one is stumping me :(

Any help is much appreciated!
You need to use JOIN by ID instead of the UNION.
Using JOIN there is no need of the sub-query.
Also ( before SELECT is not required after the INSERT INTO.

So the working query is:

INSERT INTO Company (Year, Company, Revenue) 
SELECT FR.Year, FR.Company, CF.Revenue
FROM Fortune500 FR
JOIN Comp_Financials CF ON CF.ID = FR.ID;


Added More explanation in this post, why you need to avoid UNION, and use JOIN for your requirement.