I have a question about the basic syntax of joining with derived tables.
Is this teh basic syntax that is used:
select *
from table1 a
inner join (select * from table2) as T1
on 1.ID = T1.ID
Will that work?
I have a question about the basic syntax of joining with derived tables.
Is this teh basic syntax that is used:
select *
from table1 a
inner join (select * from table2) as T1
on 1.ID = T1.ID
Will that work?
you're asking about joining two subqueries? try:
select * from
(select * from table1) t1 inner join
(select * from table2) t2 on
t1.id = t2.id
In your posted query change on 1.ID = T1.ID
to on a.ID = T1.ID
and it should work fine but why do you even need that? You can directly join with table1
and no need of inline/derived table like
select *
from table1 a
inner join
table2 T1
on a.ID = T1.ID
Also useful if you're trying to use derived table defined using VALUES
, i.e., to get around the 1000 row limit on inserts to temporary tables (multiple row insert). Make sure to specify the names of the variables/columns in the VALUES statement i.e., (ids)
, after the alias i.e., v
.
Example:
SELECT *
FROM (VALUES (1,'c1'),(2,'c2'),(3,'c3')) v (ids, textcol)
JOIN TABLE1 t1 on t1.ids = v.ids