473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with multi table delete

Ok I upgraded to 4.1.12 Max so I could start using InnoDb and be able to do
multiple table deletes among others.

I have an app system that I need to delete info from a few tables when we
delete a bogus app or a client we cant place.

Here is the query I wrote that finally worked

DELETE applications,client_rates,avail_apps,req_docs,uplo
ads FROM applications,client_rates,avail_apps,req_docs,uplo
ads where applications.cid='".$var."' or client_rates.cid='".$var."' or
avail_apps.cid='".$var."' or req_docs.cid='".$var."' or
uploads.cid='".$var."'

It worked YAY!!! BUT it deleted everything in the tables ARGH!!! good thing
I was on a test DB.

Where did I go wrong? I have tried many variations and this was the only way
it didnt error but it didnt limit to cid = 384. I keep reading the section
on multiple table deletes but it isnt making sense.

SIDENOTE: When I tested the query I hardcoded $var as 384 (id of test
record) and pasted into SQL window on phpmyadmin

thx for any help

Eric
Jul 23 '05 #1
2 1505
Unless you have relations (foreign keys) set up with your tables, I
would think that it would delete all data from all specified tables
with that query.

Also, why do you have the table names specified twice? Shouldn't:

DELETE FROM applications, client_rates, avail_apps, req_docs, uploads
WHERE applications.cid='".$var."'
OR client_rates.cid='".$var."'
OR avail_apps.cid='".$var."'
OR req_docs.cid='".$var."'
OR uploads.cid='".$var."'

work fine?

Jul 23 '05 #2
Apologies, I should have read the documentation more carefully.

Your syntax is fine, but you need some join conditions in the WHERE
clause, for example:

WHERE [...] AND applications.cid = client_rates.cid AND avail_apps.cid
= client_rates.cid AND [...]

This is based on my assumption of how your foriegn key relationships
are structured. Modify to suit your situation.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
2
by: michael | last post by:
Gotta post because this is driving me nuts. Trying to DELETE orphans. I can successfully: SELECT GroupID FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID IS NULL; but when I...
2
by: Soldier | last post by:
Hello! SELECT * FROM reviews AS r, reviews_description AS rd WHERE r.reviews_id = rd.reviews_id AND r.products_id= 108; works, DELETE FROM reviews AS r, reviews_description AS rd WHERE...
0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data in one table. All data in that table are gone...
9
by: cheryl | last post by:
I am relatively new to programming in Access for a multi user environment, and am having trouble figuring out if there is a way to accomplish one of our user requests. I am working on a multi...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
8
by: Benzine | last post by:
Hi, I have an issue with my replication at the moment. I will try to describe the scenario accurately. I am using MS SQL 2000 SP4 with Merge Replication. Subscribers connect to the publisher...
1
by: gomzi | last post by:
hi, When i try to delete rows in a table by checking the values in an other table, then i receive this error:- "unknown table 'userid' in multi delete" Here's the query...
2
by: =?Utf-8?B?TU1TSkVE?= | last post by:
How to let user delete multi rows from the BindingSource I have in my program datagridview bound it to sql table Throw Bindingsource To fill it: MyTableTableAdaptor.fill(MyDataset.Mytable); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.