SELECT
i.*,
r.name AS roomname,
c.name AS cat,
p.key AS imgkey,
p.extension AS imgext
FROM
items i,
rooms r,
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.