删除表的最后一行使用SQL查询? [英] delete the last row in a table using sql query?
问题描述
我正在尝试使用 MySql查询删除数据库中名为"marks" 的表中的最后一条记录.我试图这样做.我也在 localhost 上尝试过.我为此尝试的查询如下:
I am trying to delete the last record in the table named "marks" in the database using MySql query. I was tried to do so. Also I tried on the localhost. The query I tried for this is as follows:
DELETE MAX(`id`) FROM `marks`;
表中有8列.我想删除最后一列而不指定DELETE FROM marks where id=8
;删除第8条记录后,我想删除第6条之后的第7条记录,依此类推,直到第1条记录,而无需手动指定.
There are 8 columns in the table. I want to delete the last column without specifyingDELETE FROM marks where id=8
; After deleting the 8th record, i want to delete the 7th after that 6th and so on upto 1st record without specifying manually.
请通过示例代码帮助我解决此问题.预先感谢.
Please help me in this issue with example coding. Thanks in advance.
推荐答案
如果id
是自动递增的,则可以使用以下
If id
is auto-increment then you can use the following
delete from marks
order by id desc limit 1
这篇关于删除表的最后一行使用SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!