Grant Robinson <[EMAIL PROTECTED]> writes:

> I've been googling for a solution to this and haven't been able to find one.
> Here is my problem:
>
> I have a table named questions that looks like this:
> id|question|answer
> 1|Cat''s name|fluffy
> 2|Dog''s name|buffy
>
> When I execute the following query:
>
> select * from questions where question = 'Cat''s name';
>
> I get no results.  However, when I execute the query
> with double quotes:
>
> select * from questions where question = "Cat''s name";
>
> I get 1 row returned.  Can someone explain this discrepancy to me?

I'll first define my Terminology:
  ' = single quote (which is also known as an apostrophe)
  " = double quote

Your data actually contains TWO single quotes.  If you use signal quotes for
surrounding the string in your query, then two single quotes is the way of
escaping one single quote within the string.  If you use double quotes for
surrounding the string in your query, then single quotes need not be escaped.
Similarly, if you use double quotes for surrounding the string in your query,
then a double quote may be escaped by inserting two double quotes.

You've done one of these to get the data into the first row of your table,
thus actually inserting two single quotes in the question field:

  INSERT INTO questions
      (id, question, answer)
    VALUES
      (1, "Cat''s name", "fluffy");

  INSERT INTO questions
      (id, question, answer)
    VALUES
      (1, 'Cat''''s name', 'fluffy');

You can query your table using single quotes to surround the string, by doing:

  SELECT * from questions where question = 'Cat''''s name';

Derrell

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to