HELP needed with SQL query!!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
RossBryan
Forum Newbie
Posts: 19
Joined: Fri Aug 19, 2011 3:03 pm

HELP needed with SQL query!!!

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HELP needed with SQL query!!!

Post by requinix »

Single quotes are for strings, not names. Use backticks for names.

Code: Select all

SELECT `directories`.`folder_id`...
RossBryan
Forum Newbie
Posts: 19
Joined: Fri Aug 19, 2011 3:03 pm

Re: HELP needed with SQL query!!!

Post 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
Post Reply