473,466 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Create 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 1745
<co***************************@yahoo.com> wrote in message
news:bb**************************@posting.google.c om...
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
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...
3
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...
4
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:...
6
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...
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...
14
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...
8
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...
2
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...
12
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...
4
by: muzu1232004 | last post by:
Can anyone explain me when we use correlated subqueries rather than nested subqueries. Do all the correlated subqueries can be written in nested subqueries form as well ? What are the major...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
1
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
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.