0

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 :)

4
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by tomato.pgn
0

Are you using MySQL? Try this ...

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

Edited by Dani: n/a

0

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.....

0

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.

0

$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.

0

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.

This topic has been dead for over six months. 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.