Jump to content

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.

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.