#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    139
    Rep Power
    10

    Selecting "...WHERE mycol = '2\'' " returns same as "...WHERE mycol = '2' ". Why?


    "SELECT FROM myTable WHERE mycol = '2\'' "

    returns the same results as if you run:

    "SELECT FROM myTable WHERE mycol = '2' ".

    One has an apostrophe after the value and one doesn't. Why would mysql treat them the same? I don't understand this behavior.

    Note, if you put the apostrophe BEFORE the value, mysql reads them differently. Which would seem to be the correct behavior.
    Thanks,
    Dan

    Operating system ubuntu 12.04
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,262
    Rep Power
    4279
    try this --
    Code:
    WHERE mycol = '2'''
    two consecutive single quotes is what you use to represent a single quote

    a similar example --
    Code:
    WHERE lastname = 'O''Toole'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo