SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make changes as per id ?

    Hi,

    Can someone tell me the SQL Command to make changes to a certain number of entries.
    For example If I have 2 columns in a table namely, id & status.

    Now if I want to change status=1 on records from id=1 to 10,

    How to do this?
    Thanks.
    I love to help and also to get helped.

  2. #2

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you sir.
    I love to help and also to get helped.

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi I tried it, but it's not working.

    UPDATE [LOW_PRIORITY] [IGNORE] table_name
    SET status='1'
    [WHERE 'id'>1 AND 'id'<10]
    I love to help and also to get helped.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    remove the square brackets, which are used in the syntax in the manual to show words or clauses that are optional

    also, don't put single quotes around your column names, that just turns them into strings

    also, don't put quotes around numeric values that will be compared with or assigned to numeric columns -- it'll work in mysql (but not in other databases), but the conversion from string to number is needless overhead
    Code:
    UPDATE table_name
       SET status = 1
     WHERE id > 1 
       AND id < 10
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2010
    Location
    ONS
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Rudy Sir.
    I love to help and also to get helped.


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
  •