Jump to content

delete from multiple tables with one sql statment?


n8w

Recommended Posts

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";
			}	
}

 

 

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.