How can I reference the table (T1 JOIN T2 ON A=B JOIN T3 ON C=D)?

Hello

Is there a good guide on how to reference tables in SQL?

I am struggling to reference the output of a join, e.g.:
SELECT *
FROM (T1 JOIN T2 ON A=B JOIN T3 ON C=D) AS OUTPUT
WHERE OUTPUT.E = 1

Any idea?

Thanks!

This is not valid SQL - you cannot 'name' the results of joins. In your example, you reference the columns of each table using either the table or the table alias. Since you are not aliasing any of the tables you need to use the table.

SELECT t1.Col1
     , t1.Col2
     , t2.Col1
     , t2.Col3
     , t3.Col4
  FROM t1
  JOIN t2 ON t2.Key = t1.Key
  JOIN t3 ON t3.Key = t2.OtherKey
 WHERE t1.SomeColumn = 'SomeValue'

Try:

SELECT *
FROM (SELECT * FROM T1 JOIN T2 ON A=B JOIN T3 ON C=D) AS OUTPUT
WHERE OUTPUT.E = 1
1 Like

That's what I wrote, so does it work then?

I'm dropping out of this q. Good luck with this and future qs.

2 Likes

Ah, apologies I missed the 'SELECT' in the parenthesis.