Printable Version of Topic

Click here to view this topic in its original format

Forums _ Webmasters' Corner _ Mysql Syntax

Posted by: Maccabee Feb 27 2011, 10:57 AM

This code doesn't work.

CODE
SELECT * FROM 'bookmarks' WHERE 'group' = 'Social'

This code does.
CODE
SELECT * FROM `bookmarks` WHERE `group` = 'Social'

The working code was generated by phpmyadmin. I've seen those diagonal single quote marks, nor have I read anything about them in php books/tutorials/etc. What are they, and how do I even make them? I feel stupid asking this but I just spent an hour trying to figure out why my sql query wasn't working and that appears to be the only difference.

Posted by: mipadi Feb 27 2011, 05:54 PM

Single quotes denote a string. Table and column names are not strings, thus you can't use single quotes. However, some databases allow you to use backticks (`) around table and column names. Personally, I never use backticks around table/column names.

Posted by: Maccabee Feb 28 2011, 12:39 AM

QUOTE(mipadi @ Feb 27 2011, 04:54 PM) *
Single quotes denote a string. Table and column names are not strings, thus you can't use single quotes. However, some databases allow you to use backticks (`) around table and column names. Personally, I never use backticks around table/column names.

Oh, so I could have just been using:
CODE
SELECT * FROM bookmarks WHERE group = 'Social'

That makes sense, thanks Michael.