473,503 Members | 5,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting multiple rows that have the same field value.

Hello,

Example:

I have 100 rows that all have the field vaule of 'XYZ' I would like to
delete only 10 of those rows.

Is there such a query like "Delete 10 rows from table where table.field
= 'XYZ'"

Thanks,

Patrick

Nov 2 '05 #1
7 5656
>I have 100 rows that all have the field vaule of 'XYZ' I would like to
delete only 10 of those rows.

Is there such a query like "Delete 10 rows from table where table.field
= 'XYZ'"


Have you tried:
delete from table where table.field = 'XYZ' limit 10;
?

This is one of the reasons why a field:
id int not null auto_increment primary key
is useful. It guarantees you will be able to generate a query to just
delete what you want to delete.

Gordon L. Burditt
Nov 2 '05 #2
Hey thanks... that worked.

My table does have auto_inc, int primary key... How can I do my quiery
if the rows are not in consecutive order?

delete from table where table.id = '1' and table.id ='2' and table.id =
'10' etc....

Patrick

Nov 2 '05 #3
pa**************@gmail.com wrote:
Hey thanks... that worked.

My table does have auto_inc, int primary key... How can I do my quiery
if the rows are not in consecutive order?

delete from table where table.id = '1' and table.id ='2' and table.id =
'10' etc....


delete from table where id in (select id from table where field='XYZ'
limit 10)

First time posting and may not be right, but that'd be where I'd start from.

Cheers,
Andy
Nov 2 '05 #4
> delete from table where id in (select id from table where field='XYZ'
limit 10)


In theory that's right, but I think there's still a limitation in MySQL that
doesn't allow to use sub-selects in delete statements that refer to the same
table as the outer query. So I fear that this query will not work, yet.

Markus
Nov 2 '05 #5
>My table does have auto_inc, int primary key... How can I do my quiery
if the rows are not in consecutive order?

delete from table where table.id = '1' and table.id ='2' and table.id =
'10' etc....


There's also:

delete from table where table.id in (1, 2, 10, 86, 37, 666);

Gordon L. Burditt
Nov 2 '05 #6
Markus Popp wrote:
delete from table where id in (select id from table where field='XYZ'
limit 10)


In theory that's right, but I think there's still a limitation in MySQL that
doesn't allow to use sub-selects in delete statements that refer to the same
table as the outer query. So I fear that this query will not work, yet.


OK, well nice to know it should work in theory (do you know if it would
work in MySQL 5.0?).

More out of interest than anything else....
Cheers,
Andy
Nov 2 '05 #7
> OK, well nice to know it should work in theory (do you know if it would
work in MySQL 5.0?).


Unfortunately not.

It might be possible to do it with a join - but it might be easier to choose
the

delete from table where id in (1, 4, 6, 8);

way.

Markus
Nov 2 '05 #8

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

Similar topics

7
5643
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the...
3
1666
by: Epetruk | last post by:
Hi, I have a mySql question here on updates to multiple tables. Here's a simple schema to clarify things: Structure Table A
12
2973
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
2
2176
by: Zak McGregor | last post by:
Hi all I have a table, for simplicity's sake containing one field, called unid. for example, select unid, oid from table gives me something like this: unid | oid ---------+---------
5
2464
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name...
4
1637
by: Jim Michaels | last post by:
Is it safe to do what is below? deleting from a resultset while you are processing it? I don't know how dynamic the SQL database is. I assume you get a cursor to live dataset. Even if it is a...
52
6269
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
4
11467
by: arizal | last post by:
Hi , I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working. My php code is listed as below <?php $sql = "Select * from list;";...
3
3905
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
7207
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
7093
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...
1
7012
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
7468
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...
1
5023
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
3180
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...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.