I have this big select That I think is correct, that I have to execute but I don't know why it gives me an error. All my tables are single tables and between them I don't have any relation. Any idea about what happens? Is in the second ON
when it happens:
select DISTINCT t0_0.id_pord, t0_0.prod_fam, t0_0.prod_nam, t0_0.prod_mod
from inventory t0_0
INNER JOIN ( select DISTINCT c0.id_dev
FROM ps_det c0
INNER JOIN ( select DISTINCT c0.id_dev
FROM ps_det c0
INNER JOIN mtx_det c1
ON c0.psirtid = c1.alert_id ) t4_0
ON t0_0.id_dev = t3_0.id_dev
WHERE c0.invent = '1333'
AND c0.cust = '598' ) t3_0
ON t0_0.id_dev = t3_0.id_dev
where t0_0.prod_fam IN ('Cisco', 'Catalyst', '3750 Series')
AND t0_0.invent ='1333'
AND t0_0.cust = '598'
It gives me that error:
ERROR: invalid reference to FROM-clause entry for table "t0_0"
LINE 1: mtx_det c1 ON c0.psirtid = c1.alert_id) t4_0 ON t0_0.id_dev...
^
HINT: There is an entry for table "t0_0", but it cannot be referenced from this part of the query.
********** Error **********
ERROR: invalid reference to FROM-clause entry for table "t0_0"
SQL state: 42P01
Hint: There is an entry for table "t0_0", but it cannot be referenced from this part of the query.
Character: 352
Any idea?
You have referenced t0_0 from one of your subqueries:
select DISTINCT c0.id_dev
FROM ps_det c0
INNER JOIN ( select DISTINCT c0.id_dev
FROM ps_det c0
INNER JOIN mtx_det c1
ON c0.psirtid = c1.alert_id ) t4_0
ON t0_0.id_dev = t3_0.id_dev -- HERE'S YOUR PROBLEM
WHERE c0.invent = '1333'
AND c0.cust = '598'
Each subquery must contain its own aliases, so the subquery should be:
select DISTINCT c0.id_dev
FROM ps_det c0
INNER JOIN ( select DISTINCT c0.id_dev
FROM ps_det c0
INNER JOIN mtx_det c1
ON c0.psirtid = c1.alert_id ) t4_0
ON t4_0.id_dev = c0.id_dev -- HERE'S THE FIX
WHERE c0.invent = '1333'
AND c0.cust = '598'
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.