求助:Mysql删除时遇到的问题
下面是表结构:
mysql> desc test1;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(4) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> desc test2;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(4) | YES | | NULL | |
| grade | varchar(6) | YES | | NULL | |
| subject | varchar(20) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> select * from test1;
+----+-------+
| id | name |
+----+-------+
| 1 | Jacky |
| 2 | Tom |
| 3 | Mike |
+----+-------+
3 rows in set (0.00 sec)
mysql> select * from test2;
+------+-------+---------+
| id | grade | subject |
+------+-------+---------+
| 1 | 99.5 | English |
| 1 | 90 | Maths |
| 2 | 90 | Maths |
| 2 | 95.5 | English |
| 3 | 95.5 | English |
| 3 | 90 | Maths |
+------+-------+---------+
6 rows in set (0.00 sec)
我的目的是要将名字为的人的资料在两个表里面同时给删掉,结果报错。求高手指点。
mysql> delete from test1 as p1 ,test2 as p2 where p1.id=p2.id and p1.name='Jacky';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where p1.id=p2.id and p1.name='Jacky'' at line 1