Mixing explicit and implicit joins fails with “There is an entry for table … but it cannot be referenced from this part of the query”

前端 未结 3 1667
有刺的猬
有刺的猬 2020-12-05 09:08
SELECT
      i.*, 
      r.name AS roomname, 
      c.name AS cat, 
      p.key AS imgkey, 
      p.extension AS imgext
   FROM 
      items i, 
      rooms r, 
             


        
3条回答
  •  孤城傲影
    2020-12-05 10:00

    The SQL spec states that explicit joins are performed before implicit joins. This is an implicit join:

    FROM table1 t1, table2 t2 WHERE t1.id=t2.t1id
    

    This is an explicit join:

    FROM table1 t1 JOIN table2 t2 ON (t1.id=t2.t1id)
    

    This code bit:

    categories c 
         LEFT JOIN photos p 
            ON p.referencekey = i.key 
    

    is an explicit join and is run first. Note that at this point the table aliased as i hasn't been looked at yet, so it can't be joined yet. Note that MySQL fixed this behaviour in 5.2 I believe, and this query will no longer work there either.

提交回复
热议问题