Reputation: 1199
i am new to sql joins.. i have project that is 5 year old . Now i have to deploy it some new server .so deploy it to other server there i am facing some sql problem. here is the 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
i am getting this error
1054 - Unknown column 'd.downloads_description' in 'on clause'
i have not written this sql query.it is working fine on old server .
I am new to join and database .please can any one help me .
Upvotes: 1
Views: 131
Reputation: 247650
You are mixing both implicit and explicit join syntax which will not work.
You have the following implicit syntax where the tables are joined by commas:
FROM strings s, downloads d, products_has_downloads pd
The JOIN
syntax has a higher precedence to the comma syntax so the alias for downloads
is not available in the ON
clause.
Try using all of the same syntax. I changed your query to use only explicit JOIN
syntax:
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
Upvotes: 3