Results 1 to 14 of 14

Thread: MySQL Delete with JOINS

Threaded View

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    MySQL Delete with JOINS

    I have 4 joined tables:
    tbl_users (primary key user_id)
    tbl_user_subject_registration (foreign key user_id)
    tbl_user_results (primary key result_id, foreign key user_id)
    tbl_user_question_register (foreign key result_id)

    I would like to delete all records in all tables related to a user_id supplied. Ideally this should be within one Delete statement. I've tried various things but always get a syntax error. Can anyone point out where I'm going wrong. Latest attempt below.

    Code:
    DELETE  	tbl_users.*, tbl_user_subject_registration.*, tbl_user_results.*, tbl_user_question_register.*
    FROM		tbl_users 
    INNER JOIN	tbl_user_subject_registration 
    ON		tbl_users.user_id = tbl_user_subject_registration.user_id 
    INNER JOIN	tbl_user_results 
    ON		tbl_users.User_id = tbl_user_results.user_id 
    INNER JOIN	tbl_user_question_register 
    ON		tbl_user_results.result_id = tbl_user_question_register.result_id 
    WHERE 		tbl_users.user_id = ?
    Cheers

    DJ
    Last edited by dj4uk; Jul 14th, 2005 at 03:35 AM.

    If I have been helpful please rate my post. If I haven't tell me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width