Click to See Complete Forum and Search --> : delete from multiple tables


raj_2006
11-19-2007, 02:00 AM
Hi all,

I am trying to delete some records from more than one table.But the sql is giving the error.Here is the query

$del=mysql_query("delete from member,idol,habit where member.mid='{$_SESSION['mid1']}' or idol.mid='{$_SESSION['mid1']}' or habit.mid='{$_SESSION['mid1']}'") or die(mysql_error());

If mid=5 then in idol table there is no record containing mid=5.Is it the reason?

Please suggest what I shall do now.

Thanks for your co-operation in advance.

Regards,
Raj

chazzy
11-19-2007, 06:58 PM
you need to have records matching in all tables to delete.

but i'd really recommend that you dont' delete from multiple tables in a single statement. you never know what might happen.

raj_2006
11-19-2007, 10:37 PM
Thanks for your reply first.

Oh...yes then i think my doubt is right...In Idol table the query was not finding mid with 5 thats why it was giving an error.But if there are 10 tables and I want to delete from 10 then I have to write 10 separate queries.

Can I write sub queries here?

Regards,
Raj

chazzy
11-21-2007, 05:57 AM
yes, you can.