Mysqldeletelimit usage _ MySQL

Source: Internet
Author: User
When studying the cms system today, we found that the delete statement is followed by a limit, which is always used for select queries. I don't know why to use it, just now Baidu will share with you the limit method and a bit Advantages of mysql delete limit:

The unique LIMIT row_count option of MySQL for DELETE is used to notify the server of the maximum value of the row deleted before the control command is returned to the client. This option ensures that a DELETE statement does not take too much time. You can repeat the DELETE statement until the number of related rows is less than the LIMIT value.

If the DELETE statement contains an order by clause, all rows are deleted in the ORDER specified in the clause. This clause takes effect only when used with LIMIT. For example, the following clause is used to find the row corresponding to the WHERE clause, use timestamp_column for classification, and delete the first (oldest) row:

Delete from somelog WHERE user = 'jcol' order by timestamp_column LIMIT 1;

Delete limit usage:

Single table syntax: delete [low_priority] [quick] [ignore] from tbl_name
[Where where_definition]
[Order by...]
[Limit row_count]

Delete all rows
You can delete all rows without deleting a table. This means that the table structure, attributes, and indexes are complete:

Delete from table_name
Or:
Delete * from table_name

The following differences are specified for deletion, for example, 0, 30.

Delete from db limit 0, 30

Basically none of my tests are passed here. the delete from db limit 30 test is successful and I don't know if it's my version.

It seems that limit is followed by how many records are deleted, and the number of starting records like select is not given!

Then, if I want limit 30 to be deleted by default, it is similar to select * from db limit 0, 30,

Select from 'sheet1' where 1 limit 0, 1
Delete from 'sheet1' where 1 limit 1

When the number of records is large, we generally use limit 100

Delete from tag_list where aid = '000000' limit 6666;

The delete table connection does not support limit. how can this problem be solved?

The delete table connection does not support limit.
Mysql> delete test1 from test1 join test2 on test1.id = test2.id limit 10;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 10' at line 1
Mysql>

------ Solution ----------------------
Delete a from test1 a inner join (select id from test2 limit 10) B
On A. id = B. id;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.