At 10:41 +0200 15/9/06, Dominik Klein wrote:
I have a table with primary key id. Another field is date. Now I
want the last n entries, sorted by date.
Is this possible in one SQL statement?
ORDER BY `date` DESC LIMIT n
--
Cheers... Chris
Highway 57 Web Development -- http://highway57.co.uk/
Chris Sansom schrieb:
At 10:41 +0200 15/9/06, Dominik Klein wrote:
I have a table with primary key id. Another field is date. Now I
want the last n entries, sorted by date.
Is this possible in one SQL statement?
ORDER BY `date` DESC LIMIT n
Last n entries means I want the last (highest)
At 10:41 +0200 15/9/06, Dominik Klein wrote:
I have a table with primary key id. Another field is date. Now I
want the last n entries, sorted by date.
Is this possible in one SQL statement?
ORDER BY `date` DESC LIMIT n
Last n entries means I want the last (highest) n ids.
SELECT * FROM table WHERE id=(SELECT id FROM table ORDER BY id DESC) ORDER
BY date
-Original Message-
From: Dominik Klein [mailto:[EMAIL PROTECTED]
Sent: Friday, September 15, 2006 3:41 PM
To: mysql@lists.mysql.com
Subject: How to sort last n entries?
I have a table with primary key id.
And if your MySQL version does NOT support sub queries you can probably just
create a temporary table and then sort that one.
/Peter
-Original Message-
From: Peter Lauri [mailto:[EMAIL PROTECTED]
Sent: Friday, September 15, 2006 4:28 PM
To: mysql@lists.mysql.com
Cc: [EMAIL PROTECTED]
Peter Lauri schrieb:
SELECT * FROM table WHERE id=(SELECT id FROM table ORDER BY id DESC) ORDER
BY date
This does not limit it to n entries (order by date limit n is not
sufficient as I need last (highest) n ids). And afaik, limit is not
allowed in sub-queries.
--
MySQL General Mailing
You are correct. So that maybe leaves you with a temporary table then :)
-Original Message-
From: Dominik Klein [mailto:[EMAIL PROTECTED]
Sent: Friday, September 15, 2006 4:45 PM
To: mysql@lists.mysql.com
Subject: Re: How to sort last n entries?
Peter Lauri schrieb:
SELECT * FROM table
CREATE TEMPORARY TABLE tabletemp SELECT * FROM table ORDER BY id DESC LIMIT
30;
SELECT * FROM tabletemp ORDER BY date;
-Original Message-
From: Dominik Klein [mailto:[EMAIL PROTECTED]
Sent: Friday, September 15, 2006 4:45 PM
To: mysql@lists.mysql.com
Subject: Re: How to sort last n
that an ordinary SELECT
can contain: DISTINCT, GROUP BY, ORDER BY, LIMIT,...
- Original Message -
From: Dominik Klein [EMAIL PROTECTED]
To: mysql@lists.mysql.com
Sent: Friday, September 15, 2006 5:44 AM
Subject: Re: How to sort last n entries?
Peter Lauri schrieb:
SELECT * FROM table WHERE