简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM