Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Don't ask to ask, just ask
 
PerlMonks  

Re: non-perl SQL question

by dbwiz (Curate)
on Dec 31, 2003 at 07:55 UTC ( [id://317875]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to non-perl SQL question

Here is a pure SQL solution, which works only if the column being swapped is not a unique key.

mysql> select * from swaptable; +----+------+ | id | num | +----+------+ | 5 | 100 | | 6 | 200 | | 7 | 300 | +----+------+ 3 rows in set (0.00 sec) mysql> UPDATE swaptable SET id = CASE id WHEN 5 THEN 6 -> WHEN 6 THEN 5 END -> WHERE id IN (5,6); Query OK, 2 rows affected (0.01 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> select * from swaptable; +----+------+ | id | num | +----+------+ | 6 | 100 | | 5 | 200 | | 7 | 300 | +----+------+ 3 rows in set (0.00 sec) mysql> UPDATE swaptable SET id = CASE id WHEN 5 THEN 6 -> WHEN 6 THEN 5 END -> WHERE id IN (5,6); Query OK, 2 rows affected (0.01 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> select * from swaptable; +----+------+ | id | num | +----+------+ | 5 | 100 | | 6 | 200 | | 7 | 300 | +----+------+ 3 rows in set (0.00 sec)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://317875]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.