SQL help

GT9

Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    මචංල sql වලින් එක query එකෙන්ම table එකක rows කීපයක් එක සැරේම Update කරන්නේ කොහොමද? කියල කියල දෙන්න පුලුවන්ද? මම දන්න විදියට කරා නමුත් හරියට වැඩ කරන්නෑ.

    මම කරේ මෙහෙමයි.


    vte6srl.png
     

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    Condition ekak thiyanawanam switch-case use karanna puluwan

    මචං මට ඕන මම ඔය උඩ දාල තියෙන query එක වැඩ කරන විදියට හදාගන්න. මේක execute කරාම zero affected rows or sometimes 1 affected rows එන්නේ. :sorry::confused:
    මට හිතාගන්න බෑ ඇයි වැඩ කරන්නැත්තේ කියල:confused:

    කොහොම හරි කමක් නෑ මචං මට ඕනේ ඔය ටේබල් එකේ එක field එකක දත්ත rows කීපයක එක පාරට update කරන්න. :D
     

    twisted

    Well-known member
  • Feb 21, 2008
    34,398
    818
    113
    upon purple clouds
    you are updating different records with different item_names..you can't do this with a single query unless you have another table with item_id's and their respective names, from which you can update this specific table.
     
    • Like
    Reactions: GT9

    twisted

    Well-known member
  • Feb 21, 2008
    34,398
    818
    113
    upon purple clouds
    this might work

    update item
    set i_name = case when i_id = 1 then 'chair' when I_id = 2 then 'bed'
    when i_id = 3 then 'table' end
    where i_id in (1,2,3)
     

    oxide

    Well-known member
  • Jan 30, 2012
    2,258
    1,239
    113
    මේකෙ
    UPDATE item
    SET item_name = CASE item_id
    WHEN '1' THEN 'chair'
    WHEN '2' THEN 'bed'
    ELSE item_name
    END
    WHERE item_id IN('1', '2');


    Meka try karala balapan....might be help..
     
    • Like
    Reactions: GT9