code green 1,726
Recognized Expert Top Contributor
I have a parent table `products` that contains all company products.
The product details are divided amongst 4-5 product details child tables
such as `paper`, `pens`, `books`, `sets`, `pens_paper`.
The 'product_ids` may be in one or more of these child tables but always in `products`.
Is a single DELETE query possible that will delete all occurences of a `product_id` in the tables where the `product_id` occurs.
3 9903 Motoma 3,237
Recognized Expert Specialist
I have a parent table `products` that contains all company products.
The product details are divided amongst 4-5 product details child tables
such as `paper`, `pens`, `books`, `sets`, `pens_paper`.
The 'product_ids` may be in one or more of these child tables but always in `products`.
Is a single DELETE query possible that will delete all occurences of a `product_id` in the tables where the `product_id` occurs.
One way to do this would be to use foreign keys between the tables and have cascading deletes in place.
code green 1,726
Recognized Expert Top Contributor
Thanks for the reply but I asked for a QUERY that performs a multiple delete based on the conditions.
code green 1,726
Recognized Expert Top Contributor
I seem to have solved it without any help.
Will post my solution - --delete id 100 wherever it appears across the database--
-
DELETE FROM `table1`,`table2`,`table3` USING `table1`
-
LEFT JOIN `table2` ON `table2`.`id` = 100 AND any_other_condition_for_table2
-
LEFT JOIN `table3` ON `table3`.`id` = 100 AND any_other_condition_for_table3
-
WHERE `table1`.`id` = 100
The left join solves the problem of the possibility of the id not appearing in a certain table
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ray |
last post by:
Hello all,
I am attempting to delete multiple rows from multiple tables as
follows:
DELETE FROM attachments,responses,response_lines WHERE attachments.id
IN(2,7,11) AND responses.attachment_id=attachments.id AND
response_lines.response_id=responses.id
The error message it returns is:
|
by: Mike |
last post by:
I am not a sql person and could use some help with a delete...here is
what I want:
I have the following tables/fields (only including necessary fields)
answers
result_id
results
result_id
|
by: Eric Haskins |
last post by:
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
|
by: John Baker |
last post by:
HI again:
I have a query which selects records on tblPOmods on the basis of information on two other
tables. I wish to delete the selected transactions, and am having a problem doing it. It
tells me that if "could not delete from the specified tables". I have tried to set the
"where" to "From" for the fields I selected, but the "From" wont take and bounces back to
"where". I have tried other strategies, and got a comment "Identity table...
|
by: Darin |
last post by:
I have a table that I want to delete specific records from based on
data in other tables. I'm more familiar with Access '97, but am now
using 2003, but the database is in 2000 format. In '97, I think I
could have easily done this using joins, but I kept getting "could not
delete from specified tables" errors. Some google searching has
indicated I need to use a subquery. After many failed attempts with
different approaches, I finally...
| |
by: Jeff |
last post by:
In a subform I have a simple SQL statement that links an order details table
to a product table. The form is used to enter order details. Most fields are
obviously from the details table, with only a UOM field from the product
table.
This has worked fine for years, I thought.
The problem I seem to have is that if the user makes a mistake in putting a
product in the order they then naturally want to delete the line out of the
order....
|
by: jpr |
last post by:
Hello,
My database has 5 tables.
WHen I add data to one table, it runs an append query that copies three
records to other 4 tables.
The main table is MASTER. The data I copy are: ID, SSN and PURGE DATE.
I would like to create a delete query that would delete all records in
all tables that show a date older that the one in the PURGE DATE. I use
|
by: Bob Bridges |
last post by:
Start with two tables, parent records in one and child records in the other,
a one-to-many relationship. Create a select statement joining the two.
Display the query in datasheet mode. When I delete a row, only the child
record is deleted from the source tables; the parent record is still
there...which is what I wanted.
Now display fields from that query in a continuous form. When I delete a
record from that form, one of the child...
|
by: MRounds |
last post by:
Hi
Have looked through many forums but cannot find a solution for this.
I have a table where i store certain dates and i want to use this table in several queries to delete records from multiple tables by using a macro to run the queries.
I can use DISTINCTROW to delete rows that are equal to a date but cannot figure out how to delete rows that are between a range of dates (stored in .
Example of my query :
DELETE...
|
by: clloyd |
last post by:
I have a database with over 20 tables. I need to delete one to many record(s) in all tables by using a loop code. Some tables with have one record, multiple records or no records for the criteria given. I can not do cascade delete because there are to many tables and I don't want to write 20 plus delete queries. Does anyone have any ideas how to accomplish this.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |