SQL Query Help

Hey. I can’t really figure out how to get this query to work. Any help would be greatly appreciated!

Tables:

covar
->tId1
->tId2
->covar

asx200
->id
->tickerSymbol

Where tId1 & tId2 correspond to ids in asx200.

I want to write a select statement which returns the covar and the tickerSymbols which correspond to both tId1 and tId2. So for example:

covar: 1, 2, .001

asx200:
1,BHP
2,CWB

The SELECT statement would return:

BHP,CWB,.001

Any help would be greatly appreciated. I’ve been looking around at different JOIN statements, but can’t get it to work with this example.

Thanks a lot.

Nick.

Thanks for that! Works perfectly.

You are on the right track, JOIN is the way to go. You’ll have to join the asx200 table two times to the covar table (using aliasses to identify them):


SELECT
    a1.tickerSymbol AS tickerSymbol1
  , a2.tickerSymbol AS tickerSymbol2
  , covar
FROM covar
INNER JOIN asx200 AS a1
ON a1.id = covar.tId1
INNER JOIN asx200 AS a2
ON a2.id = covar.tId2