0

I have two delete function and would like to make this as one. So I can use this on my webpage. But not sure how? Anyone willing to help me :D

DELETE
       FROM test
       WHERE 
       Tes_ID=$Tes_ID;

     DELETE
       FROM question
       WHERE 
       Tes_ID=$Tes_ID
4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by xxreenaxx1
0

Deferent tables deferent queries... Why that bothers you?

Edited by jkon: n/a

0

I think Tes_ID is common for both tables. If so, try with the below query.

DELETE FROM test as t1
 WHERE t1.Tes_ID = '$Tes_ID' 
   AND t1.Tes_ID IN (SELECT t2.Tes_ID 
                     FROM question as t2
                    WHERE t2.Tes_ID = '$Tes_ID')

Edited by paulrajj: n/a

0

@jkon: because I am trying to delete both table using PHP and it doesn excute both of the query.

@paulraj.. I am getting an error message, which I been getting for all the other methods I have tired.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as t1 WHERE t1.Tes_ID = 12 AND t1.Tes_ID IN (SELECT t2.Tes' at line 1

@ardav... I do have foreign key. These two tables are actually linked by Tes_ID.

0

I think they need to be constrained though. ROLLUP should automatically delete any related records.

0

@xxreenaxx1, I edited my post by using joins to delete the records. Here is below,

DELETE t1, t2 FROM 
	`question` AS t1 
	LEFT JOIN `test` AS t2 
	ON t1.Tes_ID = t2.Tes_ID 
	WHERE t1.Tes_ID = '1'

Edited by paulrajj: n/a

0

@ardav.. Thank you for the help

@paulraj... it worked. Thank you :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.