Displaying records in a cyclic fashion

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
minds_gifts
Forum Commoner
Posts: 63
Joined: Mon Feb 10, 2003 4:23 am

Displaying records in a cyclic fashion

Post by minds_gifts »

How can i limit the no of records displaying from a table?To be more precisely, this is what i would like to do:

Say i've 100 records in a table.Today, I would like to show 1 to 40 records.Tomorrow from 41 to 80 and then 81 to 20 on the next day.So, something like in a cyclic fashion.

Would be glad if somebody can help me.

Many thanks
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Use the Limit clause if this is a MySql database:

From the Manual:
=================
SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15
To retrieve all rows from a certain offset up to the end of the result set, you can use -1 for the second parameter:
mysql> SELECT * FROM table LIMIT 95,-1; # Retrieve rows 96-last.
If one argument is given, it indicates the maximum number of rows to return:
mysql> SELECT * FROM table LIMIT 5; # Retrieve first 5 rows
==================

I think SqlServer has a similar function - Top N
DB2's flavor uses Fetch First N only

Phil J.
Post Reply