SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why did this query mess my db table?

    Just ran this query and it has made the value in all recors in 1 column, the same. why did it do that?

    Code MySQL:
    update statistics
    set Domain_Viewed = 'example.com'
    where Domain_Viewed = ('www.example.com' or 'http://www.example.com')

    bazz

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your query is equivalent to:
    Code:
    UPDATE statistics
    SET Domain_Viewed = 'example.com'
    WHERE Domain_Viewed = 'www.example.com'
    OR TRUE
    Because a literal string when considered as a boolean is true, resulting in that query matching all rows. You can't omit the field you're comparing to, the parentheses don't create that effect.

    There are two correct forms for what you meant:

    Code:
    UPDATE statistics
    SET Domain_Viewed = 'example.com'
    WHERE Domain_Viewed = 'www.example.com' 
    OR Domain_Viewed = 'http://www.example.com'
    Code:
    UPDATE statistics
    SET Domain_Viewed = 'example.com'
    WHERE Domain_Viewed  IN ('www.example.com', 'http://www.example.com')

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan. That's a mistake I won't make again, in a hurry

    bazz


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •