1

Is it possible to get a table record depending on the row number?

For example, I have a table with 40 records and I need to get the 27th record. I need some query like SELECT * FROM my_table WHERE **ROWNUM** = 27.

1
  • You can but not with ROWNUM that is Oracle specific. Commented May 21, 2018 at 13:32

2 Answers 2

1

You are looking for offset:

select t.* from my_table t order by ??? -- you need to specify a column or expression here limit 1 offset 26; 

Two notes. There is no such thing as the 27th row of a table. SQL tables represent unordered sets. There is only an ordering if a column specifies the ordering. That is the purpose of the order by. Often this might be the primary key for the table.

Second, the offset (unlike most things in SQL) is zero-based. So an offset of "1" means "skip one record" -- or "start with the second". Hence an offset of "26".

Sign up to request clarification or add additional context in comments.

Comments

1

If I have understood you correctly, you are looking for simething like this?

SELECT * FROM some_table t where @row = 26; 

1 Comment

Yep, I need something like this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.