SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having some trouble with a MYSQL Query

    Hey everyone, this problem has brought me to this site so I hope there can be some help and learning found

    Basically, what I have is an older database that I've had to transfer over to new sites. We have thousands of entries into one of my tables and I need to change a whole column from 0 to null.

    I'm not that much of a novice anymore, and I know how to change all of the column to null, but my problem lies in about 100 scattered entries that I do NOT want to change in this column. My code so far is...

    UPDATE `database_name`.`table_name`
    SET `column_name` = ''
    WHERE `table_name`.`column_name` = 0;


    TL;DR for this, I need to change 900 entries to null without changing 100 entries that are scattered throughout the table.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    UPDATE database_name.table_name 
       SET column_name = NULL 
     WHERE column_name = 0
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still getting Affected rows: 0 with that query.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by TradesMatt View Post
    I'm still getting Affected rows: 0 with that query.
    okay, please run this and tell me what you get...
    Code:
    SELECT COUNT(*) 
      FROM database_name.table_name 
     WHERE column_name = 0
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •