Hello,

I am getting a bit confused regarding apostrophes in my SQL statement. I can get it to work but I would like to understand why it works when it does or, conversely, why it doesn't work when it doesn't. If you know what I mean. Anyway - here goes:

This doesn't work and it produces an error:

SELECT detail FROM options WHERE option = 'site name'

This doesn't work but simply returns an empty data set:

SELECT detail FROM options WHERE 'option' = 'site name'

This does work:

SELECT detail FROM options WHERE option = 'site name'

I am having trouble getting the correct apostrophe into the above code - option should be encased in the same apostrophe that seems to delineate inline code and I can't figure out how to escape it.

As you can see the difference is all about the apostrophes.

Any explanation would be most welcome, thank you.

Simon.

This is just me trying to figure out how to escape the apostrophe:
SELECT detail FROM options WHERE ``option`` = 'site name'

1 & 3 above look the same to me as well. I dont see why you are trying to escape the apostrophe.

Yes, sorry about one and three looking the same ... I can't figure out how to get the inline code editor to display properly - here's three again:

SELECT detail FROM options WHERE `option` = 'site name'

Do a screen shot and do it as an image

option is a reserved word, therefore it must be enclosed in backticks. That's why 1 does not work.

Query 2 works as it simply does a string comparison that returns false, hence no record set.