delete top 2 in Access
Asked Answered
H

3

6

What is the correct syntax for this: delete top 2 * FROM table1 in Microsoft Access? I am trying to delete the first 2 rows, and I don't have an id field. Also, I know it's possible to do: select top 2 * FROM table1, so it's hard to think they haven't thought of the same for delete. Thank you!

Otherwise I will just insert top 1 into a temp table, delete all from the original and then reinsert from the temporary. I'm actually interested in preserving one row with a certain condition. But don't understand why I need 3 steps for this when in Sql Server it's much simpler. And if they thought of using top wisely, why did they stop at select and haven't implemented this for the other instructions?

Heinie answered 19/3, 2013 at 5:20 Comment(0)
A
8

The syntax is as follows, I always found it a little strange and was of the same thinking as you:

DELETE FROM (SELECT TOP 2 * FROM Table1)
Analeptic answered 19/3, 2013 at 12:45 Comment(0)
T
1
DELETE * FROM (SELECT TOP 2 * FROM myTableName ORDER BY myTableName.IdNr) AS Deletes;

Tested in Microsoft Access 2016 and working as query or working for Access-VBA

Trahern answered 11/10, 2019 at 10:29 Comment(1)
So, to delete the last records, could you ORDER BY columnName DESC?Pavier
G
-1

The correct syntax is:-

delete top(2) from table1
Gramnegative answered 19/3, 2013 at 5:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.