RE: How to select the 10 last items from a table?

2001-01-31 Thread The Tilghman

Try sorting in DESCending order.

SELECT * FROM item ORDER BY id DESC LIMIT 10;

-Tilghman

-- 
"There cannot be a crisis today.  My schedule is already full."
 --Henry Kissinger

 -Original Message-
 From: Remco van den Berg [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, January 30, 2001 17:29
 
 On Tue, Jan 30, 2001 at 11:48:22PM +0300, Rus wrote:
  May be it could work
  SELECT  * FROM item ORDER BY ID LIMIT count(*)-10,10
 
 mysql SELECT  id FROM lid ORDER BY ID LIMIT count(*)-10,10;
 ERROR 1064: You have an error in your SQL syntax near 
 'count(*)-10,10' at line 1
 
  or
  SELECT  * FROM SELECT  * FROM item ORDER BY ID DESC LIMIT 
 10 ORDER BY ID
 
 mysql select * from select * from lid order by id DESC limit 
 10 order by id;
 ERROR 1064: You have an error in your SQL syntax near 'select 
 * from lid order by id DESC limit 10 order by id' at line 1
 
 
 I think you have to make use of at least two queries. One to 
 get MAX(id) and
 one for the actual query:
 
 mysql select MAX(id) from lid;
 +-+
 | MAX(id) |
 +-+
 | 489 |
 +-+
 1 row in set (0.00 sec)
 mysql select id from lid order by id limit 479,10;
 
 But that only works when all id's up to the last one exist.
 If you delete records from the table calculating 479 by 
 substracting 10 
 from MAX(id) doesn't work.
 
 So, the only solution left, I can think of, is to make use of 
 an temporary
 table (in memory) to store the results of your query which 
 are in the wrong
 order. And then query the temporary table to get right order.

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: How to select the 10 last items from a table?

2001-01-31 Thread Remco van den Berg

On Wed, Jan 31, 2001 at 08:00:23AM -0600, The Tilghman wrote:
 Try sorting in DESCending order.
 
 SELECT * FROM item ORDER BY id DESC LIMIT 10;
 
 -Tilghman

People,

Thanks for all the answers, but the question was:

  "How to get the last 10 items in incrementing order."

Please read thread before answering.

-Remco


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: How to select the 10 last items from a table?

2001-01-31 Thread Gerald L. Clark

Remco van den Berg wrote:
 
 On Wed, Jan 31, 2001 at 08:00:23AM -0600, The Tilghman wrote:
  Try sorting in DESCending order.
 
  SELECT * FROM item ORDER BY id DESC LIMIT 10;
 
  -Tilghman
 
 People,
 
 Thanks for all the answers, but the question was:
 
   "How to get the last 10 items in incrementing order."
 
 Please read thread before answering.
 
 -Remco

I've been reading the thread.
You were told how to get the last 10 records.
That is the only way  to get them.
Unfortunately, that means they will be in reverse order.
You must be reading them into an array somewhere, so you
can easily access them in either order once you have stored them.

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: How to select the 10 last items from a table?

2001-01-31 Thread Tim Samshuijzen



I think the only way to do it is first get the amount of items:

   SELECT COUNT(*) FROM item;

if you use PHP, store the count in a variable called $count.
subtract 10 from count:

$limit = 10;
if($count  $limit) {
  $limit = $count;
}
$count = $count - 10;
if($count  0) {
  $count = 0;
}

then do the following:

   SELECT * FROM item ORDER BY id LIMIT $count,$limit;


Tim Samshuijzen



At 09:03 31-1-2001 -0600, you wrote:
Remco van den Berg wrote:
 
 On Wed, Jan 31, 2001 at 08:00:23AM -0600, The Tilghman wrote:
  Try sorting in DESCending order.
 
  SELECT * FROM item ORDER BY id DESC LIMIT 10;
 
  -Tilghman
 
 People,
 
 Thanks for all the answers, but the question was:
 
   "How to get the last 10 items in incrementing order."
 
 Please read thread before answering.
 
 -Remco

I've been reading the thread.
You were told how to get the last 10 records.
That is the only way  to get them.
Unfortunately, that means they will be in reverse order.
You must be reading them into an array somewhere, so you
can easily access them in either order once you have stored them.

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail
[EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php





-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: How to select the 10 last items from a table?

2001-01-31 Thread René Tegel

This works:

select * from db.table A, db.table B WHERE A.id=B.id order by B.id,A.id desc
limit 10;

regards
rene


- Original Message -
From: "Remco van den Berg" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, January 31, 2001 3:15 PM
Subject: Re: How to select the 10 last items from a table?


 On Wed, Jan 31, 2001 at 08:00:23AM -0600, The Tilghman wrote:
  Try sorting in DESCending order.
 
  SELECT * FROM item ORDER BY id DESC LIMIT 10;
 
  -Tilghman

 People,

 Thanks for all the answers, but the question was:

   "How to get the last 10 items in incrementing order."

 Please read thread before answering.

 -Remco


 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: How to select the 10 last items from a table?

2001-01-30 Thread Scott Gerhardt

SELECT * FROM item
ORDER BY ID
LIMIT 10

or change to "ORDER BY ID DESC" to get the desired result.

- Scott

 May be it could work
 SELECT  * FROM item ORDER BY ID LIMIT count(*)-10,10
 or
 SELECT  * FROM SELECT  * FROM item ORDER BY ID DESC LIMIT 10 ORDER BY ID




 - Original Message -
 From: Karlsson Andreas-andkar01 [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Tuesday, January 30, 2001 6:00 PM
 Subject: How to select the 10 last items from a table?


 Hi,
 I have a table were all rows have their own ID. How can I select only the
 last items out of this table?
 This command fixes it but I receive the items in the wrong order that I
 would like them...
 SELECT * FROM item ORDER BY ID DESC LIMIT 10
 brgds
 Andreas

 Andreas Karlsson
 MAGNET- Motorola Applications Global Network
 Campus Grsvik 2
 371 75 Karlskrona
 Phone: +46-455-379 306
 E-mail:[EMAIL PROTECTED]
 
 Become a MAGNET member - register at:
 http://www.motorola.com/developers/wireless/

 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
 [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php





 -
 Before posting, please check:
http://www.mysql.com/manual.php   (the manual)
http://lists.mysql.com/   (the list archive)

 To request this thread, e-mail [EMAIL PROTECTED]
 To unsubscribe, e-mail
 [EMAIL PROTECTED]
 Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: How to select the 10 last items from a table?

2001-01-30 Thread Remco van den Berg

On Wed, Jan 31, 2001 at 02:02:05AM +0300, Rus wrote:
 He need 10 last records ordered by id.
 
 You also can try this
 SELECT  *,count(*) as c FROM item GROUP BY ID LIMIT c-10,10

mysql select *,count(*) as c from lid group by id limit c-10,10;
ERROR 1064: You have an error in your SQL syntax near 'c-10,10' at line 1

 or
 SELECT  *,count(*)-10 as c FROM item GROUP BY ID LIMIT c,10

mysql select *,count(*)-10 as c from lid group by id limit c,10;
ERROR 1064: You have an error in your SQL syntax near 'c,10' at line 1

Nope

Still no one-query-solution

-Remco

-- 

Remco van den Berg   Admin/SO/helpdesk DSE  
  ICQ: 47514668 [EMAIL PROTECTED] http://www.dse.nl/   


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php