Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete info from 4 tables at once but with different name for key

    Hello,

    I have four tables, let's say

    Code:
    tbl1			tbl2			tbl3		user       
    -------			-------			-------		----------
    id				id				id			id
    userid			userid			userid		info
    info			info			info
    Now how to delete everything of one user in a single query?

  • #2
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Here is the only way to do this:

    Code:
    Delete from tbl1 where userid=11;Delete from tbl2 where userid=11;Delete from tbl3 where userid=11;Delete from tbl4 where userid=11;

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    too bad.., i love to do everything in a single query

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SSJ View Post
    Here is the only way to do this:

    Code:
    Delete from tbl1 where userid=11;Delete from tbl2 where userid=11;Delete from tbl3 where userid=11;Delete from tbl4 where userid=11;
    wrong!
    see: http://dev.mysql.com/doc/refman/5.0/en/delete.html

    I solved it like this:
    Code:
    		DELETE FROM `tbl1`, `tbl2`, `tbl3`
    		USING `tbl`, `tbl2`, `tbl3`,
    		WHERE
    		(`tbl1`.`id` = `tbl3`.`tbl1id` OR `tbl1`.`userid` = '23')
    		OR
    		(`tbl2`.`id` = `tbl3`.`tbl2id` OR `tbl2`.`userid` = '23')


  •  

    Posting Permissions

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