0

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'

Edited by slyme: Trying to make inline code display properly

4
Contributors
5
Replies
15
Views
2 Years
Discussion Span
Last Post by pritaeas
0

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

0

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'

Edited by slyme: Trying to make inline code display properly

1

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.

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.