文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>mysql update delete join问题

mysql update delete join问题

时间:2010-06-10  来源:ubuntuer

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)


 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载