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

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 1688
<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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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
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...

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.