Pregunta

The problem is as following: I'm using a subquery and I need to join

WITH subselect_from_A AS (
    SELECT A.A_ID FROM A
)
SELECT B.D_ID FROM B, subselect_from_A WHERE B.B_ID = 
A.A_ID
/* or instead: subselect_from_A.A_ID */

;

How Do I reference the column form the subselect?

¿Fue útil?

Solución

First of all, you should stop using deprecated implicit joins and use explicit joins instead. Then you can use table aliases for this:

WITH subselect_from_A AS (
    SELECT A.A_ID FROM A --doesn't really seem like a sub-select
)
SELECT B.D_ID, A.A_ID
FROM B
INNER JOIN subselect_from_A AS A
    ON B.B_ID = A.A_ID;

Otros consejos

Same way you would with a regular table.

WITH subselect_from_A AS (
    SELECT A.A_ID FROM A
)
SELECT B.D_ID, subselect_from_A.A_ID FROM B, subselect_from_A
WHERE B.B_ID = subselect_from_A.A_ID;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top