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

 

 

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.