1

我是 sql joins 新手。我有 5 年的项目。现在我必须部署它一些新的服务器。所以将它部署到其他服务器我面临一些 sql 问题。这是 qyery 。

SELECT DISTINCT d.*,DATE_FORMAT(d.downloads_updated, '%c/%d/%Y') AS updated,DATE_FORMAT(d.downloads_created, '%c/%d/%Y') AS created, s2.strings_english as title, s2.strings_english as description 
FROM strings s, downloads d,
 products_has_downloads pd 
inner JOIN strings s2 ON d.downloads_description = s.strings_id WHERE d.downloads_id = pd.downloads_id AND s.strings_id = d.downloads_title AND d.downloads_status = 'Live' AND d.downloads_level = 'Public'
 ORDER BY d.downloads_updated DESC LIMIT 5

我收到这个错误

1054 - Unknown column 'd.downloads_description' in 'on clause'

我还没有写这个 sql 查询。它在旧服务器上运行良好。

我是新加入和数据库。请任何人都可以帮助我。

4

1 回答 1

3

您正在混合使用不起作用的隐式和显式连接语法。

您具有以下隐式语法,其中表由逗号连接:

FROM strings s, downloads d, products_has_downloads pd 

JOIN语法比逗号语法具有更高的优先级,因此子句中的别名downloads不可用。ON

尝试使用所有相同的语法。我将您的查询更改为仅使用显式JOIN语法:

SELECT DISTINCT d.*,
  DATE_FORMAT(d.downloads_updated, '%c/%d/%Y') AS updated,
  DATE_FORMAT(d.downloads_created, '%c/%d/%Y') AS created, 
s2.strings_english as title, 
s2.strings_english as description 
FROM strings s
INNER JOIN downloads d
  ON d.downloads_description = s.strings_id
INNER JOIN products_has_downloads pd 
  on d.downloads_id = pd.downloads_id
inner JOIN strings s2 
  on s2.strings_id = d.downloads_title
WHERE d.downloads_status = 'Live' 
  AND d.downloads_level = 'Public'
ORDER BY d.downloads_updated DESC 
LIMIT 5
于 2013-02-06T11:01:44.150 回答