user1157751
user1157751

Reputation: 2457

SQL - Get a reference to a table in a subquery

Is it possible to access a table from a subquery?

Select d.table_c.*
from (with table_c as (select *
                       from table_a)
      select *
      from table_b
      where table_a.id = table_b.id) as d

table_c is inside the subquery of d, I've tried to access it using d.table_c, but it doesn't seem to work.

Upvotes: 0

Views: 30

Answers (1)

ASP
ASP

Reputation: 666

You cannot use CTE as subquery. But you can write like below.

;WITH table_c
as
(SELECT * FROM table_a)
SELECT *
from table_b b
INNER JOIN table_c c on c.id = b.id

Upvotes: 1

Related Questions