title: Error SQL state: 42P01 In postgres
body: <p>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 <code>ON</code> when it happens:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>It gives me that error: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>Any idea?</p>