Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4842546
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: 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)


 

阅读(1481) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

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 回复 | 举报