473,771 Members | 2,392 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 5671
>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
5658
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 students on the screen at the same time, modify some, mark some for deletion and even have blank fields at the end to add a new record. In HTML which is generated I label each row and input field with a name/number combination i.e <input type=text...
3
1680
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
3012
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 getting any records inserted. For troubleshooting, I cut the form down to 1 textbox and when submitted it populated 5 rows of the same data. So I know I'm connected, but not getting the LOOP and NEXT correct? How do I set this up so many records can be...
2
2205
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
2491
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 they entered. Also, an image that allows them to delete shows beside the name upon creation. The delete removes the name from the table and pushes the other names to the top. Simple stuff, however, if I delete the last name displayed(the bottom of...
4
1654
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 cursor as opposed to a table, will the cursor's integrity be ruined if the current record is deleted? $q2=mysql_query("SELECT * FROM table1 WHERE id1=5", $link); while ($row2=mysql_fetch_array($q2)) { //do some stuff with resultset...
52
6351
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
4
11484
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;"; $result=mysql_query($sql) or die ("<br> Could not Retrieve Data <br>"); $num_rows=mysql_num_rows($result); While ($row =mysql_fetch_array($rs))
3
3927
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 messing up. Problems:
0
9454
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
10261
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
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
3609
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.