Jump to content

Can't figure out how to end this MySQL statement


harvey_birdman

Recommended Posts

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.

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.

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.