n8w Posted June 10, 2009 Share Posted June 10, 2009 I am sure I am doing this the long way... Is there a way to delete all records from multiple tables with one sql statement? right now I am doing it like this if( $user_id){ echo "Account Deleted"; //delete users $sql = 'DELETE FROM users WHERE user_id = "'.$user_id.'" LIMIT 1'; $retid = mysql_query($sql); # check for errors if (!$retid) { $error.=( mysql_error()); $error.= "fail"; } //delete illustrator $sql2 = 'DELETE FROM illustrators_table WHERE user_id = "'.$user_id.'" LIMIT 1'; $retid2 = mysql_query($sql2); # check for errors if (!$retid2) { $error.=( mysql_error()); $error.= "fail"; } } Quote Link to comment https://forums.phpfreaks.com/topic/161681-delete-from-multiple-tables-with-one-sql-statment/ Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 Is there a way to delete all records from multiple tables with one sql statement? Yes, the proper syntax is in the MySQL manual - DELETE. Multiple-table syntax: DELETE [LOW_PRIORITY] [QUICK] [iGNORE] tbl_name[.*] [, tbl_name[.*]] ... FROM table_references [WHERE where_condition] Quote Link to comment https://forums.phpfreaks.com/topic/161681-delete-from-multiple-tables-with-one-sql-statment/#findComment-853117 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.