473,788 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reasonable delete alternative to subqueries?

I'd like to do something like:

delete from a where id in (select * from b where pattern like
'%something%')

I may or may not have the syntax right. I know that this sort of
subquery isn't available until mysql 4.1. 4.1 beta is taking too long
to release and I need something now, so here's what I'm doing now:

replace a (id) select -refId id from b where pattern like
'%something%'

So I'm marking/flagging the rows that will need to be deleted. Next,
I delete them:

delete from a where id < 0

I've tested this, and it actually works. id is a primary key btw.

good or not good?
Jul 20 '05 #1
3 1711
<co************ *************** @yahoo.com> wrote in message
news:bb******** *************** ***@posting.goo gle.com...
I'd like to do something like:

delete from a where id in (select * from b where pattern like
'%something%')

I may or may not have the syntax right. I know that this sort of
subquery isn't available until mysql 4.1. 4.1 beta is taking too long
to release and I need something now, so here's what I'm doing now:

replace a (id) select -refId id from b where pattern like
'%something%'

So I'm marking/flagging the rows that will need to be deleted. Next,
I delete them:

delete from a where id < 0

I've tested this, and it actually works. id is a primary key btw.

good or not good?


Right idea, but not good because it will fail when there are many
connections, each trying to delete records. You could flag the records with
the session id. To get this id, use the connection_id() function.

I wonder if we could use the temporary table extension MySql provides, along
with the update/delete with many tables idea. The temporary table is valid
for this connection session only and is visible only to this session. Give
it a shot.

create temporary table adel (
aid int(1) unsigned not null references a(id),
unique index theindex (aid)
);

insert into adel (aid)
select id from a where ...;

delete from a, inner join adel on a.id = adel.aid;

At this point, I expect adel to have zero records.
Jul 20 '05 #2
co************* **************@ yahoo.com wrote:
I'd like to do something like:

delete from a where id in (select * from b where pattern like
'%something%')

I may or may not have the syntax right. I know that this sort of
subquery isn't available until mysql 4.1. 4.1 beta is taking too long
to release and I need something now, so here's what I'm doing now:


[snip]

This article should help you:
http://www.electrictoolbox.com/artic...-table-delete/

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 20 '05 #3
"Chris Hope" wrote:
co************* **************@ yahoo.com wrote:
I’d like to do something like:

delete from a where id in (select * from b where pattern like
’%something%’)

I may or may not have the syntax right. I know that this sort of
subquery isn’t available until mysql 4.1. 4.1 beta is taking

too long
to release and I need something now, so here’s what I’m

doing now:

[snip]

This article should help you:
http://www.electrictoolbox.com/artic...-table-delete/


Excellent, Chris. Thanks I bet 90% of us did not know how to use
this before (I did not for sure)

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-Reason...ict133954.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=450381
Jul 20 '05 #4

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

Similar topics

0
15005
by: Murali | last post by:
Hi All I was reading thro the posting(s) of Thomas Kyte and his nifty approach to doing updates without the need for unnecessary correlated subqueries. An alternative to correlated subquery using this technique is: update ( select columnName, value from name, lookup
3
1776
by: compu_global_hyper_mega_net_2 | last post by:
I'd like to do something like: delete from a where id in (select * from b where pattern like '%something%') I may or may not have the syntax right. I know that this sort of subquery isn't available until mysql 4.1. 4.1 beta is taking too long to release and I need something now, so here's what I'm doing now: replace a (id) select -refId id from b where pattern like
4
2181
by: Yossi Naggar | last post by:
Hello to everyone, I am an experienced user in MSSQL Server. Lately I have been started using MySQL. I managed to create my database and tables. When I wanted to execute the following query: delete from adminpages where parentid IN ( select DISTINCT A.id from adminpages AS A where A.name='galeries' );
6
35418
by: Saiyan Vejita | last post by:
I have the following SELECT query, the results of which I would delete from the table they're pulled from: SELECT A.* FROM SalesOrderPartPrices A WHERE EXISTS( SELECT 'Exists' FROM SalesOrderPartPrices B WHERE (A.SalesOrderNo = B.SalesOrderNo) AND (A.PartNo = B.PartNo) AND (A.UnitPrice = B.UnitPrice) AND
2
20477
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 so.order_id = sol.order_id)
14
8089
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...
8
3079
by: starman7 | last post by:
i have a table with objects in categories and their positions. there will be several rows with category 400, and they will have various positions, i want to delete only the row with the lowest position. i can select the row i want to delete, but don't know how to delete just this row. here's my select:
2
2495
by: chrisoftoday | last post by:
Firstly, I know there's a lot of old posts on this topic but none seem to be relevant to my problem (selecting from a single table rather than several different tables)... I have a table with a user identifier (uID) and a movie identifier (movID) and need to select the movie identifiers that appear in the table for uID-1 but not for uID-2, using an alternative to NOT IN as it isn't supported by the version of MySQL that I'm using. I'd...
12
3374
by: yufufi | last post by:
Hello, How does delete know how much memory to deallocate from the given pointer? AFAIK this informations is put there by new. new puts the size of the allocated memory before the just before the beginning of the array. But I couldn't find this information by looking at the memory. (Via VS2005 - C++) My second questions is, if there is a mechanism to know how much memory is allocated for the array, why don't we use it for things like...
0
9656
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, 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...
0
9498
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,...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8993
agi2029
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...
1
7517
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 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...
0
6750
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();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.