2

I know its possible to select nth row.

For example

select from table limit 1 offset 3;

Is it possible to delete nth row?

1
  • 6
    Tables represent unordered sets. There is no such thing as the nth row in a table. Commented Mar 30, 2017 at 12:59

1 Answer 1

1

If you have an id and something to order by and/or partition by you can delete using row_number() like so:

drop table if exists t;
create table t (id int, val int);
insert into t values (1,9),(2,8),(3,7),(4,6),(5,5);

delete 
from t
where id in (
  select id
  from (
    select id, row_number() over (order by val asc) as rn
    from t
    ) s
  where s.rn = 3);

select * from t;

rextester demo: http://rextester.com/XJHB50704

returns:

+----+-----+
| id | val |
+----+-----+
|  1 |   9 |
|  2 |   8 |
|  4 |   6 |
|  5 |   5 |
+----+-----+
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.