Test table:
CREATE TABLE' Test ' (' ID ')int( One) not NULLauto_increment, ' name 'varchar(255) not NULL,`Order' varchar (255)DEFAULT NULL,
PRIMARY KEY(' id ')) ENGINE=InnoDB auto_increment=4 DEFAULTCHARSET=UTF8;
Insert test data:
INSERT into' Bbkb_busticket '. ' Test ' (' id ', ' name ', 'Order`)VALUES('1','Zhang San','0');INSERT into' Bbkb_busticket '. ' Test ' (' id ', ' name ', 'Order`)VALUES('2','John Doe','1');INSERT into' Bbkb_busticket '. ' Test ' (' id ', ' name ', 'Order`)VALUES('3','King eight eggs','2');
Swap the value of a field in two rows: (Replace Id=1, 2 with two order)
UPDATEJOIN test T2on=2and=1 SET t1. ' Order= T2. 'order', T2. 'order' =T1. 'order';
Exchange values for two columns in two columns: (Swap the name and order of Id=1 for a second)
UPDATE SET = T2. 'order', T1. 'order=WHERE= t2.id
MYSQL, exchanging two columns of values and two rows of values with one statement, respectively