473,216 Members | 2,074 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,216 software developers and data experts.

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 5647
>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
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
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
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
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
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
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
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
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
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.