INNER JOIN MySQL错误:1054('on子句'中的未知列'prodotti.id')

时间:2013-11-21 15:48:19

标签: mysql syntax-error

我收到一条我不明白的SQL错误。这是我得到的错误:

Database error: Invalid SQL: 
SELECT distinct prodotti.nome, prodotti.id, prodotti.image_news, 
       imgprod.path, imgprod.alt 
  FROM `prodotti`, `categorie`, `prodcat`, 
       `gruppi` INNER JOIN imgprod ON prodotti.id = imgprod.idprod 
        LEFT OUTER JOIN radiation 
            ON prodotti.radiation_id = radiation.id_radiation 
        LEFT OUTER JOIN installation 
            ON prodotti.installation_id = installation.id_installation 
 WHERE 1=1 and prodotti.id = prodcat.idprod 
   and prodcat.idcat = categorie.id 
   and categorie.idgruppo = gruppi.id 
   and (gruppi.nome like 'ANT%' OR gruppi.nome like 'WIR%') 
   AND radiosystem LIKE '%VHF%' 
 GROUP BY prodotti.id ORDER BY prodotti.nome ASC

这是我得到的另一个错误:

INNER JOIN MySQL Error: 1054 (Unknown column 'prodotti.id' in 'on clause')

这适用于旧服务器,但在使用php 5.3.16的新服务器上我收到这些错误。你能解释一下这个错误意味着什么吗?

1 个答案:

答案 0 :(得分:2)

仅使用显式ANSI样式连接重写的查询可能类似于

SELECT p.id, p.nome, p.image_news, i.path, i.alt 
  FROM prodotti p JOIN prodcat pc
    ON p.id = pc.idprod JOIN categorie c 
    ON pc.idcat = c.id JOIN gruppi g 
    ON c.idgruppo = g.id JOIN imgprod i 
    ON p.id = i.idprod LEFT JOIN radiation r
    ON p.radiation_id = r.id_radiation LEFT JOIN installation n 
    ON p.installation_id = n.id_installation 
 WHERE 1 = 1 
   AND (g.nome LIKE 'ANT%' OR g.nome LIKE 'WIR%') 
   AND radiosystem LIKE '%VHF%' 
 GROUP BY p.id, p.nome, p.image_news, i.path, i.alt
 ORDER BY p.nome

除了没有看到确切的表格模式之外,我们不可能说出来。