0

I am trying to combine two tables, S&P2 and Foundation, so that I can transfer information from corresponding rows in S&P2.Tic into Foundation.Ticker.

I created this code; however, no matter how I alter the code SQL always returns the Error Code 1054: Unknown Column/Field. This field is always S&P2. If this error does not pop up, SQL will just continually run.

USE nasdaqProj;

SELECT `S&P2`.`fyear`
FROM `nasdaqProj`.`S&P2`;

select * from Foundation;

SELECT `S&P2`.`conm` As sconm, `S&P2`.`tic` as 'ticker'
from nasdaqProj.`S&P2`
left outer join Foundation
ON `S&P2`.conm LIKE CONCAT (Foundation.comnm,'%')
and `S&P2`.fyear = Foundation.year

UNION

SELECT `S&P2`.`conm` As sconm, `S&P2`.`tic` as ticker

from nasdaqProj.`S&P2`
right outer join Foundation
ON `S&P2`.conm LIKE CONCAT (Foundation.comnm,'%')
and `S&P2`.fyear = Foundation.year;

I have been stuck on this for a while, and after reading the other error code 1054 question answers I was still unable to apply the solutions to my code.

1 Answer 1

0

Have you tried breaking the query into as small statements as possible? Try running each side of the union statement separately.

Sign up to request clarification or add additional context in comments.

3 Comments

That will run, but it only returns Foundation and S&P2 columns separately; however, I need to combine the S&P2 tickers with the Foundation comnm.
So both sides of the union will run separately? Maybe try wrapping each side of the union in parentheses.
Also, the second half of the union statement will probably need to be updated so that the fields selected are from the Foundation table as S&P2 will be null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.