我正在尝试从表中删除14条记录,并显示一条错误消息
关键字“ order”附近的语法不正确
我没有运气尝试过this solution,并且几乎在所有地方都在搜索这种简单的修复程序,但是我找不到正确的解决方案。请帮忙。
DELETE FROM
MeterReading
ORDER BY
id ASC
limit
14
答案 0 :(得分:3)
我认为您需要
with t1 as
(
select top 14 * from t FROM MeterReading
order by id ASC
) delete from t1
limit
是mysql语法,因此您必须将其删除
答案 1 :(得分:3)
尝试一下。 limit
在SQL Server中无效。
;WITH CTE AS
(
SELECT TOP 14 *
FROM MeterReading
ORDER BY id
)
DELETE FROM CTE
答案 2 :(得分:1)
SQL Server
具有TOP (n)
子句,因此,请使用而不是LIMIT
子句:
DELETE
FROM MeterReading m
WHERE ID IN (SELECT TOP (14) id FROM MeterReading ORDER BY id ASC);
但是,您也可以执行以下操作:
DELETE mr
FROM (SELECT TOP (14) mr.id
FROM MeterReading mr
ORDER BY mr.id
) mr;
答案 3 :(得分:1)
从MeterReading中删除ID在其中(从MeterReading ORDER BY ID中选择前14个ID)
答案 4 :(得分:0)
您正在寻找的解决方案是针对mySQL而非SQL Server编写的,
要在SQL Server中删除,请使用
Delete From TableName WHERE yourcondition
答案 5 :(得分:0)
[编辑] 这是正确的方法。
DELETE FROM MeterReading
SELECT TOP 14 *
FROM MeterReading
ORDER BY id ASC