[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Using PhP/MySQL, how can I delete records from two tables with a common user_id

Posted on 2014-08-02
Medium Priority
Last Modified: 2014-08-02
I'm trying to delete all records (by user_id) from two tables. Below is my script. It's not generating errors but its also not deleting records.  Hopefully someone can lend some clarity!

// Get the user ID of the user to delete
$user_id = $_GET['user_id'];

// Build the DELETE statement
$delete_query = sprintf("DELETE FROM users t1 INNER JOIN user_training_items t2 ON t1.user_id=t2.user_id WHERE t1.user_id= %d",

// Delete the user from the database

Open in new window

Question by:chaddcarr
LVL 58

Accepted Solution

Gary earned 400 total points
ID: 40236588
DELETE users, user_training_items FROM users INNER JOIN user_training_items
WHERE users.user_id= user_training_items.user_id and users.user_id= %d

Open in new window


Author Closing Comment

ID: 40236623
Thanks, Gary!  Exceptional advice as always!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month20 days, 7 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question