I have two tables
The movies table holds the PK for a particular movie. The chapters.mc_mov_id is the FK. I've been going through the data and have noticed that there are a number of records in the chapters table with an mc_movie_id that doesn't exist anymore in the movies table.Code:CREATE TABLE IF NOT EXISTS `movies` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; CREATE TABLE IF NOT EXISTS `chapters` ( `mc_mov_id` int(10) unsigned NOT NULL DEFAULT '0', `mc_lang` char(2) CHARACTER SET latin1 NOT NULL, `mc_chapter_num` int(10) NOT NULL, PRIMARY KEY (`mc_mov_id`,`mc_chapter_num`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
For instance
SELECT * FROM chapters WHERE mc_mov_id=698 - contains records.
SELECT * FROM movies WHERE id=698 - contains no records.
How do I delete the records from chapters that don't have a corresponding record in the movies table?









Bookmarks