harvey_birdman Posted June 12, 2010 Share Posted June 12, 2010 Hi y'all. Sorry for my noob-ness in this post. I'll do my best to explain. I have 2 tables, one called 'users' and the other called 'user_profiles' The only thing that these 2 tables have in common is a row called 'userID' If I want to delete the users that have their 'status' as 'inactive', I do this... DELETE FROM users WHERE status = 'inactive' ...which works fine except it obviously only deletes those users (from the users table). I don't know how to modify that statement so that it also deletes the related user_profile as well. I hope I explained that properly. Any help would be great. Cheers. Link to comment https://forums.phpfreaks.com/topic/204534-cant-figure-out-how-to-end-this-mysql-statement/ Share on other sites More sharing options...
jcbones Posted June 12, 2010 Share Posted June 12, 2010 You should be able to use: $sql = "DELETE `users`,`user_profiles` FROM `users` INNER JOIN `user_profiles` WHERE `users`.`userID` = `user_profiles`.`userID` AND `users`.`status` = 'inactive'"; MySQL DELETE Syntax NOTICE* This code is un-tested. Link to comment https://forums.phpfreaks.com/topic/204534-cant-figure-out-how-to-end-this-mysql-statement/#findComment-1070982 Share on other sites More sharing options...
harvey_birdman Posted June 12, 2010 Author Share Posted June 12, 2010 U da man. That worked a treat. Joins have never been my strong point so I should try and get acquainted with the more. Cheers. Link to comment https://forums.phpfreaks.com/topic/204534-cant-figure-out-how-to-end-this-mysql-statement/#findComment-1071001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.