SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    UPDATE table SET various_fields = 0 WHERE various_fields = 5

    These big queries are hard for me, can one advise me on how i might do this?

    I know how to do it the SUPER LONG way, but not even the medium way or short way.
    Code MySQL:
    UPDATE users SET 
                `weapon` = 0
                , `head` = 0
                , `chest` = 0
                , `arms` = 0
                , `hands` = 0
                , `legs` = 0
                , `feet` = 0
                , `belt` = 0
                , `ring` = 0
                WHERE 
                    ANY OF THE VALUES = 5


    I have one rudy gave me similar to this but its for a SELECT but I cant figure out if its possible to implement in an UPDATE:

    Code MySQL:
    SELECT $value FROM items WHERE `id` IN
    {
    weapon
    , head
    , chest
    , arms
    , hands
    , legs
    , feet
    , belt
    , ring);

  2. #2
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Would this do the trick?

    Code MySQL:
    UPDATE users SET 
                `weapon` = 0
                , `head` = 0
                , `chest` = 0
                , `arms` = 0
                , `hands` = 0
                , `legs` = 0
                , `feet` = 0
                , `belt` = 0
                , `ring` = 0
                WHERE 
                    5 IN (weapon, head, chest, arms, hands, legs, feet, belt, ring);

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    good one, mal
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes Thank you I really gotta make use of that IN


    I wouldnt have figured this out on my own thats for surte

  5. #5
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Yea, it's a lot easier than doing this!
    Code MySQL:
    UPDATE users SET 
                `weapon` = 0
                , `head` = 0
                , `chest` = 0
                , `arms` = 0
                , `hands` = 0
                , `legs` = 0
                , `feet` = 0
                , `belt` = 0
                , `ring` = 0
                WHERE 
                    weapon = 5 OR
                    head = 5 OR
                    chest = 5 OR
                    arms = 5 OR
                    hands = 5 OR
                    legs = 5 OR
                    feet = 5 OR
                    belt = 5 OR
                    ring = 5;

  6. #6
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't know that this works:
    Code MySQL:
    5 IN (weapon, head, chest, arms, hands, legs, feet, belt, ring)
    I used to have
    Code MySQL:
    weapon in (1, 2, 3, 5 ..)

    But anyway, thanks for the idea.


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
  •