Page 1 of 1

HELP needed with SQL query!!!

Posted: Thu Apr 05, 2012 11:18 pm
by RossBryan
Can anybody tell me why i am encountering the following problem with the follow SQL query when run in myPHPadmin:

Code: Select all

SELECT 'directories'.'folder_id', 'directories'.'timestamp', 'directories'.'name', LEFT ('directories'.'description', 30)as 'description' COUNT('files'.'file_id') as 'file_count' 
FROM 'directories' LEFT JOIN 'files' 
ON 'directories'.'folder_id' = 'files'.'folder_id' 
WHERE 'directories'. 'user_id' = 1
GROUP BY 'directories'. 'folder_id'
Showing the error message:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.'folder_id', 'directories'.'timestamp', 'directories'.'name', LEFT ('directorie' at line 1

Re: HELP needed with SQL query!!!

Posted: Fri Apr 06, 2012 1:12 am
by requinix
Single quotes are for strings, not names. Use backticks for names.

Code: Select all

SELECT `directories`.`folder_id`...

Re: HELP needed with SQL query!!!

Posted: Fri Apr 06, 2012 4:32 pm
by RossBryan
Thanks its sorted now, achieved it it by taking single quotes from around identifiers completely when pointing to them. My mistake didnt reliase:

Code: Select all

SELECT directories.folder_id, directories.timestamp, directories.name, LEFT (directories.description, 30)as description, COUNT(files.file_id) as file_count
FROM directories
LEFT JOIN files
ON directories.folder_id = files.folder_id
WHERE directories. user_id = 1
GROUP BY directories. folder_id