Welcome to AC Web.
Results 1 to 3 of 3
  1. #1

    Swap values - MySQL (DB)


    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Hey there, I need to switch values of column `basearmor` from table `creature_classlevelstats` where `class` = 1 AND `class = 2`

    I mean, I want to `class = 1` have `basearmor` from `class = 2` and `class = 2` have `basearmor` from `class = 1` (swap)

    I don't know about MySQL, hope I can get some help here.

    - - - Updated - - -

    Sorry, I meant to SWAP values

    - - - Updated - - -

    I've got this so far, obviously not working because I don't understand:
    Code:
    --need TO store the original VALUES
    SELECT
        *,CASE WHEN `class`=1 THEN 2 ELSE 1 END AS basearmor
        INTO #Temp
        FROM `creature_classlevelstats`
        WHERE `class` IN (1,2)
    
    --swap VALUES
    UPDATE Y
        SET basearmor1=t.basearmor1
            ,basearmor2=t.basearmor2
        FROM `creature_classlevelstats`        Y
            INNER JOIN #Temp  t ON y.id =t.basearmor
        WHERE `class` IN (1,2)
    Extracted from Google.
    Last edited by molinita; 04-06-2020 at 06:07 PM.

  2. #2
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    3,067
    nvm, i have to re-think my idea lol
    Last edited by Tok124; 04-07-2020 at 03:39 PM.

  3. #3

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Anyone?

    - - - Updated - - -

    up

    - - - Updated - - -

    bump... still could not make a value swap via SQL Query...

 

 

Posting Permissions

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