Connecting Tech Pros Worldwide Forums | Help | Site Map

Delete records in two tables

Familiar Sight
 
Join Date: Jan 2008
Posts: 199
#1: Sep 9 '09
I have mysql db. there are tow tables. Per one record in first tables, has many record in second table.
Ex: table 1
Expand|Select|Wrap|Line Numbers
  1. IDT1       name
  2. ===    =====
  3. 1        Animals
  4. 2        Vehicles
  5. 3        Fruits
  6.  
Table 2
Expand|Select|Wrap|Line Numbers
  1. IDT2      IDT1          des
  2. ===       ====        =====
  3. a            1           cat
  4. b             2           car
  5. c             1           dog
  6.  
If user delete 1 row in table 1 , should delete 1st and 3rd row in second table. How can I do that?

paulrajj's Avatar
Member
 
Join Date: Sep 2008
Location: India
Posts: 35
#2: Sep 12 '09

re: Delete records in two tables


Expand|Select|Wrap|Line Numbers
  1.  
  2. DELETE t.*, a.* FROM table1 AS t LEFT JOIN
  3.            table2 AS a ON t.idt1 = a.idt1 WHERE t.idt1 = 1
  4.  
  5.  
hope it helps.
Reply