I want to delete rows based on condition. Let me explain in detail,
table1
-----------------
| t1id | t1detail |
|--------------- |
| 1 | iii |
| 2 | jjj |
| 3 | iik |
| 4 | jjk |
-----------------
table2
------------------------
| t2id | t1id | t1detail |
|----------------------- |
| 1 | 1 | iii |
| 2 | 1 | jja |
| 3 | 3 | iib |
| 4 | 1 | jjc |
| 5 | 2 | iid |
| 6 | 3 | jje |
| 7 | 4 | iif |
| 8 | 2 | jjg |
| 9 | 3 | iih |
| 10 | 4 | jj3 |
------------------------
Now I need to delete table1 id(t1id) at the same time in table2 all id assigned from tablet1 should be deleted.
for example, Suppose I need to delete t1id = 1 mean, it should delete from table1 and table2
in table1
1 | iii
in table2
1 | 1 | iii
2 | 1 | jja
4 | 1 | jjc
should be deleted. Kindly advice me to do in mysql
I tried with
$query = "DELETE FROM table1 INNER JOIN table2 ON table1.t1id = table2.t1id WHERE table1.t1id = {$id};
$result = mysql_query($query, $connection);
but not successfull