Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL delete all rows where id is greater than the given number

Tags:

Is there an Sql query I can run that will enable me to delete all rows where the ID is greater than let's say 10?

Something like this.

I have two columns, ID and Name

DELETE FROM table_name WHERE ID=>10; 
like image 868
ProEvilz Avatar asked Feb 02 '15 22:02

ProEvilz


People also ask

Which query can be used to delete rows from a table books WHERE the value in column no pages?

So the delete statement is used to delete rows from a table using the where clause to select only the rows to be deleted. Always use a unique identifier to locate the rows that you need to delete. To delete all the rows in a table, always use TRUNCATE TABLE.

Can we use WHERE clause in delete?

DELETE Syntax Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!

Can we use limit in delete query in MySQL?

You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the condition in the WHERE clause. You cannot use ORDER BY or LIMIT in a multiple-table DELETE .

How do I delete rows faster in MySQL?

To delete rows in a MySQL table, use the DELETE FROM statement: DELETE FROM products WHERE product_id=1; The WHERE clause is optional, but you'll usually want it, unless you really want to delete every row from the table.


1 Answers

Your query was nearly perfect ;)

Just try

DELETE FROM table_name WHERE ID>9; 

You could also use

DELETE FROM table_name WHERE ID>=10; 

As you already mention.

like image 130
frlan Avatar answered Sep 19 '22 12:09

frlan