Question about selecting rows

Started by Hrishikesh Deshmukhalmost 20 years ago3 messagesgeneral
Jump to latest
#1Hrishikesh Deshmukh
hdeshmuk@gmail.com

Hi All,

I have a question about selecting rows, my table has 20,000 rows, i want to
look at rows 5000 to 10,000.
How does one use the select statement in this case since i don't have a
specific case to use where?!!!!!!!!!

Thanks in advance.

Hrishi

#2Doug McNaught
doug@mcnaught.org
In reply to: Hrishikesh Deshmukh (#1)
Re: Question about selecting rows

"Hrishikesh Deshmukh" <hdeshmuk@gmail.com> writes:

Hi All,

I have a question about selecting rows, my table has 20,000 rows, i want to
look at rows 5000 to 10,000.

There is no defined row ordering in SQL unless you use ORDER BY, so
you need to specify how you want to sort it first.

How does one use the select statement in this case since i don't have a
specific case to use where?!!!!!!!!!

Something like:

SELECT * FROM mytable ORDER BY index_column LIMIT 5000 OFFSET 5000;

If you leave out the ORDER BY you will get the rows in a non-specified
order, which may be different and (in this case) include a different
set of rows the next time you run it.

-Doug

#3Michael Fuhr
mike@fuhr.org
In reply to: Hrishikesh Deshmukh (#1)
Re: Question about selecting rows

On Sat, Apr 15, 2006 at 06:44:29PM -0400, Hrishikesh Deshmukh wrote:

I have a question about selecting rows, my table has 20,000 rows, i want to
look at rows 5000 to 10,000.

See OFFSET and LIMIT in the SELECT documentation. Be sure to read
the advice about using ORDER BY.

http://www.postgresql.org/docs/8.1/interactive/sql-select.html#SQL-LIMIT

--
Michael Fuhr