全部博文(930)
分类: Mysql/postgreSQL
2010-06-10 18:14:35
1. update join
update info1 a inner join info2 b on a.id=b.id set a.name=b.name;
2. delete join
delete from info1 , info2 using info1 inner join info2 on info1.id=info2.id;
mysql> desc info1;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | | | |
| name | varchar(20) | YES | | NULL | |
+-------+------------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
mysql> desc info2;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | | | |
| name | varchar(20) | YES | | NULL | |
+-------+------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from info1;
+----+---------+
| id | name |
+----+---------+
| 1 | zj1 |
| 2 | kenthy1 |
| 3 | jimmy1 |
| 4 | jeremy |
+----+---------+
4 rows in set (0.00 sec)
mysql> select * from info2;
+----+---------+
| id | name |
+----+---------+
| 1 | zj2 |
| 2 | kenthy2 |
| 3 | jimmy2 |
+----+---------+
3 rows in set (0.00 sec)
mysql> update info1 a inner join info2 b on a.id=b.id set a.name=b.name;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select * from info1;
+----+---------+
| id | name |
+----+---------+
| 1 | zj2 |
| 2 | kenthy2 |
| 3 | jimmy2 |
| 4 | jeremy |
+----+---------+
4 rows in set (0.00 sec)
mysql> delete from info1 , info2 using info1 inner join info2 on info1.id=info2.id;
Query OK, 6 rows affected (0.02 sec)
mysql> select * from info1;
+----+--------+
| id | name |
+----+--------+
| 4 | jeremy |
+----+--------+
1 row in set (0.00 sec)
mysql> select * from info2;
Empty set (0.00 sec)
chinaunix网友2010-06-14 17:34:19
cheapWomens MBT Chapa Shoe MBT Lami Shoe discountMBT Shoes on sale! MBT Shoes can lessen back pain and relieve neck tension. You will have a comfortable feeling like walking on sandy beach or on soft moss when you wear 回复 | 举报