hi to all, I'm new in mysql and I have a problem regarding deleting rows. I have 38 tables in database and I want to delete rows in all tables with specific ID that is executed in just 1 click.

For example, I executed ID number 1 then it will delete all rows in all table with an ID Number 1.

It seems my current query is horrible. Ex.

1. query(DELETE table1 with ID=1)
2. query(DELETE table2 with ID=1)
3. query(DELETE table3 with ID=1)
4. query(DELETE table4 with ID=1)
5. query(DELETE table5 with ID=1)

Thank you so much for your help :)

Recommended Answers

All 6 Replies

Are you using MySQL? Try this ...

mysql_query("DELETE FROM table1 WHERE id = 1");

hey cs cgal..this guy has posted two threads for the same problem...merge it into one....
and the problem he asked is that there are 5-6 tables and he want to delete records from all with a specific id.....

Are you using MySQL? Try this ...

mysql_query("DELETE FROM table1 WHERE id = 1");

Hi cscgal, I'm using MySQL. My problem is I want to delete the specific ID executed in all tables in our database. For example, they will going to delete this ID # 1, then all ID # 1 in all tables will going to delete.

Now, is there any other way to compressed that and make it as a single query?

Note: I have tables that is no field name ID.

Right now I'm using this following sample query.

$myQueryVar1 = mysql_query("DELETE FROM mytable1 WHERE id='$idExecuted'");
$myQueryVar2 = mysql_query("DELETE FROM mytable2 WHERE id='$idExecuted'");
$myQueryVar3 = mysql_query("DELETE FROM mytable3 WHERE id='$idExecuted'");
$myQueryVar4 = mysql_query("DELETE FROM mytable4 WHERE id='$idExecuted'");
$myQueryVar5 = mysql_query("DELETE FROM mytable5 WHERE id='$idExecuted'");

Thank you so much for your help Ms. cscgal and tomato.pgn.

$myQueryVar1 = mysql_query("DELETE FROM mytable1 WHERE id='$idExecuted'");
$myQueryVar2 = mysql_query("DELETE FROM mytable2 WHERE id='$idExecuted'");
$myQueryVar3 = mysql_query("DELETE FROM mytable3 WHERE id='$idExecuted'");
$myQueryVar4 = mysql_query("DELETE FROM mytable4 WHERE id='$idExecuted'");
$myQueryVar5 = mysql_query("DELETE FROM mytable5 WHERE id='$idExecuted'");

The above code is right and should work.
What is problem you are facing.

hi vibhadevit, I want to place it in a single query so that when we add new tables we don't have to edit the file anymore. Let the script search all the tables and look the table that have an ID with the specific ID executed. Is that possible? I'm using PHP. Thank you for your concern.

i told you one of the solution is to use triggers.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.