473,413 Members | 1,989 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,413 software developers and data experts.

DELETE within SELECT

Dom
Hey there,

I would like to execute the following query to perform deletes.
Unfortunately it only returns a list of the delete queries without
actually performing them. How can I get the deletes to be executed? I
am running MySQL 4.0.20-standard.

$query = "SELECT concat('DELETE FROM temp WHERE prodid =
\'',prod.ProdID, '\';') AS '' FROM prod LEFT JOIN catalog ON
prod.ProdID = catalog.ProdID WHERE catalog.ProdID IS NULL";

All help really appreciated!

Thanks,

Dom
Jul 23 '05 #1
1 8585
Dom wrote:
Hey there,

I would like to execute the following query to perform deletes.
Unfortunately it only returns a list of the delete queries without
actually performing them. How can I get the deletes to be executed? I
am running MySQL 4.0.20-standard.

$query = "SELECT concat('DELETE FROM temp WHERE prodid =
\'',prod.ProdID, '\';') AS '' FROM prod LEFT JOIN catalog ON
prod.ProdID = catalog.ProdID WHERE catalog.ProdID IS NULL";


Well, you can execute this query and get results back, right? So each
row of the result set becomes a new $query that you can execute.

Another option is to use a multi-table delete, which is a clever (but
non-standard) extension to SQL implemented in MySQL. For example:

DELETE FROM temp
USING temp INNER JOIN prod ON temp.prodid = prod.ProdID
LEFT OUTER JOIN catalog ON prod.ProdID = catalog.ProdID
WHERE catalog.ProdID IS NULL

See http://dev.mysql.com/doc/mysql/en/delete.html for more info on the
multi-table deletes.

Regards,
Bill K.
Jul 23 '05 #2

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

Similar topics

2
by: Rotsj | last post by:
Hi, if i run the following query: select * from std_order_lines sol where exists(select * from std_orders so, customers c where so.customers_id = c.customers_id and c.test_customer = 'Y' and...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
by: Mark Reed | last post by:
Hi all, Please help. I have a table with 2 fields of which I am trying to change a select query into a delete query. the select query is: SELECT Table1.Date, Min(Table1.Ball) AS MinOfBall...
5
by: PaulMac | last post by:
Hi, Hopefully this is a simple one. IF x =3 then i want to delete the first 3 records in tabley (Similar to a TOP select statement: Select Top 3 * from tabley)
6
by: Bernd Smits | last post by:
Hi, I would like to delete a record (with commandbutton) of a table associated to a combobox, when I select a certain value in the combobox (the value I select is associated with the record that I...
9
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3)...
6
by: Ivan | last post by:
Hello to all and thanks for answer to my topics. I made one stored procedure that delete one table, but when call/execute the procedure this show SQL0532N A parent row cannot be deleted...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
31
by: matthewslyman | last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion. My form design involves a recursively...
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
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
isladogs
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...
0
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...

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.