3
Reply

If a dataset contains 50 rows, how to fetch rows between 10 and 20 only?

Rajeev Kumar

Rajeev Kumar

2y
2.7k
0
Reply

If a dataset contains 50 rows, how to fetch rows between 10 and 20 only?

    If you want sql query for above assuming your table name is mytable below query will work

    select * from mytable
    order by id
    Offset 10 Rows
    fetch next 10 Rows only;

    Assuming your dataset is in a table named my_table and has a column that can be used to order the rows (e.g. an auto-incrementing ID column named “id”), you can use the following SQL query to fetch rows 10 through 20:

    1. SELECT *
    2. FROM my_table
    3. ORDER BY id
    4. LIMIT 10 OFFSET 9;

    Explanation:

    • ORDER BY id orders the rows by the ID column (or any other column you want to use for ordering).
    • LIMIT 10 limits the results to 10 rows.
    • OFFSET 9 skips the first 9 rows, which will return rows 10 through 20. Note that the offset value is zero-indexed, so to skip the first 9 rows, you need to set the offset to 9.

    The specific way to fetch rows between 10 and 20 from a dataset depends on the programming language and technology being used. Here’s an example using C# and LINQ (Language Integrated Query):

    1. var data = Enumerable.Range(1, 50).ToList(); // sample dataset
    2. var result = (from item in data
    3. where item >= 10 && item <= 20
    4. select item).ToList();

    In this example, the data variable is a list of integers ranging from 1 to 50. The result variable contains a list of integers that are between 10 and 20 (inclusive). The where clause in the LINQ query filters the items in the data list that are greater than or equal to 10 and less than or equal to 20.