mysql> desc video_info;
+-------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| vid | varchar(255) | NO | MUL | NULL | |
| title | varchar(255) | YES | MUL | NULL | |
| url | varchar(255) | YES | | NULL | |
| metaUrl | varchar(255) | YES | | NULL | |
| description | text | YES | | NULL | |
| keywords | varchar(500) | YES | | NULL | |
| videoType | varchar(255) | YES | | NULL | |
| webSite | varchar(255) | YES | MUL | NULL | |
| imgPath | varchar(255) | YES | | NULL | |
| createDate | timestamp | YES | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
mysql> desc video_info_streamtypes;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | MUL | NULL | |
| type | varchar(255) | NO | | NULL | |
| timelength | double | NO | | NULL | |
| size | double | NO | | NULL | |
| videoId | int(11) | NO | MUL | NULL | |
+------------+--------------+------+-----+---------+----------------+
其中video_info_streamtypes的videoId为外键关联video_info表的id。
现需要删除video_info_streamtypes中找不到对应video_info表中数据的记录,语句如下:
delete from video_info_streamtypes where not exists (select * from video_info where video_info.id=video_info_streamtypes.videoId )