Delete X rows from table

user2854563

I want to delete X rows from a table having an equal column values. For a better way of this question, I'm writing this question in a sql query way, please understand:

DELETE id FROM table_name WHERE column_value = 1 AND user_id = 2;

And this query should delete 3 rows. How can I achieve this?

Willem Van Onsem

One can use the LIMIT keyword (according to the MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/delete.html):

DELETE FROM table_name WHERE column_value = 1 AND user_id = 2 LIMIT X;

Where you replace X with a number.

EDIT: (regarding the comment)

I copied this from the specifications, looks like it solves the problem you are trying to tackle:

The MySQL-specific LIMIT row_count option to DELETE tells the server the maximum number of rows to be deleted before control is returned to the client. This can be used to ensure that a given DELETE statement does not take too much time. You can simply repeat the DELETE statement until the number of affected rows is less than the LIMIT value.

LIMIT is a MySQL specific instruction, you cannot use it as a generic SQL query, other databases like PostgreSQL might fail to execute such query.

Another remark: you specified id in the query. If you remove rows, you should not specify columns.

I've tested it using SQL Fiddle and it succeeded: http://sqlfiddle.com/#!2/13ccb7/1/0 and http://sqlfiddle.com/#!2/258203/1/0.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delete rows from table

From Dev

Select and Delete exactly x rows from MySql table

From Dev

Delete rows from Table X if fields in Table Y hold the same data

From Dev

How to delete rows from a table in database X, where the ID exists in Database Y

From Dev

Delete duplicate rows from table with no unique key

From Dev

Better "delete rows from table" performance

From Dev

Delete Rows from a Constrained Reference Table

From Dev

delete rows from a table using MySQL Scheduler

From Dev

Delete rows from table recursively using JQ

From Dev

Delete duplicate rows from a BigQuery table

From Dev

Delete few rows from db table

From Dev

Cannot delete rows from a table SQL

From Dev

multiple queries to delete rows from table

From Dev

delete rows from a table that are not present in another

From Dev

How to delete some similar rows from a table?

From Dev

mysql delete duplicate rows from table

From Dev

Delete rows from Table, remove unpaid transaction

From Dev

Delete rows from table inner join

From Dev

How to delete from table then delete what deleted rows referenced? (postgresql)

From Dev

How to Use Delete Triggers to Delete Rows From Same Table?

From Dev

Delete rows from a data table that exists in another data table

From Dev

Delete rows from a data table that exists in another data table

From Dev

How to delete rows from a table based on a join with another table?

From Dev

How to delete rows from one table matching another table?

From Dev

Delete all data rows from an Excel table (apart from the first)

From Dev

Delete duplicate rows in a table

From Dev

Delete rows in Data table

From Dev

Postgresql: How to delete rows from table constrained by date?

From Dev

Delete rows from a table without checking that they exist first

Related Related

  1. 1

    Delete rows from table

  2. 2

    Select and Delete exactly x rows from MySql table

  3. 3

    Delete rows from Table X if fields in Table Y hold the same data

  4. 4

    How to delete rows from a table in database X, where the ID exists in Database Y

  5. 5

    Delete duplicate rows from table with no unique key

  6. 6

    Better "delete rows from table" performance

  7. 7

    Delete Rows from a Constrained Reference Table

  8. 8

    delete rows from a table using MySQL Scheduler

  9. 9

    Delete rows from table recursively using JQ

  10. 10

    Delete duplicate rows from a BigQuery table

  11. 11

    Delete few rows from db table

  12. 12

    Cannot delete rows from a table SQL

  13. 13

    multiple queries to delete rows from table

  14. 14

    delete rows from a table that are not present in another

  15. 15

    How to delete some similar rows from a table?

  16. 16

    mysql delete duplicate rows from table

  17. 17

    Delete rows from Table, remove unpaid transaction

  18. 18

    Delete rows from table inner join

  19. 19

    How to delete from table then delete what deleted rows referenced? (postgresql)

  20. 20

    How to Use Delete Triggers to Delete Rows From Same Table?

  21. 21

    Delete rows from a data table that exists in another data table

  22. 22

    Delete rows from a data table that exists in another data table

  23. 23

    How to delete rows from a table based on a join with another table?

  24. 24

    How to delete rows from one table matching another table?

  25. 25

    Delete all data rows from an Excel table (apart from the first)

  26. 26

    Delete duplicate rows in a table

  27. 27

    Delete rows in Data table

  28. 28

    Postgresql: How to delete rows from table constrained by date?

  29. 29

    Delete rows from a table without checking that they exist first

HotTag

Archive