MySQL查询删除ID最低的记录?
要删除ID最低的记录,可以使用以下语法:
delete from yourTableName order by yourColumnName limit 1;
让我们首先创建一个表:
mysql> create table DemoTable(
Id int,
Name varchar(20)
);
以下是使用insert命令在表中插入记录的查询:
mysql> insert into DemoTable values(10,'Larry');mysql> insert into DemoTable values(100,'Mike');
mysql> insert into DemoTable values(30,'Sam');
mysql> insert into DemoTable values(90,'Chris');
mysql> insert into DemoTable values(9,'Carol');
以下是使用select命令显示表中记录的查询:
mysql> select *from DemoTable;
这将产生以下输出:
+------+-------+| Id | Name |
+------+-------+
| 10 | Larry |
| 100 | Mike |
| 30 | Sam |
| 90 | Chris |
| 9 | Carol |
+------+-------+
5 rows in set (0.00 sec)
以下是删除ID最低的记录的查询:
mysql> delete from DemoTable order by Id limit 1;
让我们显示表中的所有记录,以检查最低ID是否已删除:
mysql> select *from DemoTable;
这将产生以下输出
+------+-------+| Id | Name |
+------+-------+
| 10 | Larry |
| 100 | Mike |
| 30 | Sam |
| 90 | Chris |
+------+-------+
4 rows in set (0.00 sec)
以上是 MySQL查询删除ID最低的记录? 的全部内容, 来源链接: utcz.com/z/331505.html