2

I'm trying to delete the session and exercises related to that session using:

$delete_session =

"DELETE FROM sessions, exercises 
USING sessions 
INNER JOIN exercises 
ON sessions.session_id = exercises.session_id 
WHERE sessions.session_id= '$delete_id'";

The above query works if there are exercises linked to the session but doesn't fire if the session has no exercises.

Can I use the above query and below one together?

"DELETE FROM sessions WHERE session_id= '$delete_id'";

How could I get it that the session will delete with or without exercises linked to it?

1
  • 2
    Try with LEFT JOIN Commented Sep 19, 2015 at 16:01

1 Answer 1

1

You should use LEFT INNER JOIN

$delete_session =
"DELETE FROM sessions, exercises 
USING sessions 
LEFT INNER JOIN exercises 
ON sessions.session_id = exercises.session_id 
WHERE sessions.session_id= '$delete_id'";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.