re: Nested MySQL Statements

2002-12-14 Thread Egor Egorov
On Friday 13 December 2002 14:43, Peter Vertes wrote:

 Is it possible to do nested select statements with MySQL ?  Basically
 I'm trying to display the last 5 rows that got inserted into a table.  My
 SQL query looks like this:

 select * from tablename limit ((select count(*) from tablename) - 5), -1;

 In theory it works for me :) but MySQL complains.  Is it possible to do
 nested queries with MySQL ?  Does anyone have a better way of displaying
 the last x amount of rows inserted into a table ?  Thanks in advance...

There is no internal order in the table, there is no last record and nope the 
first row in the table. If you have auto_increment column, you can do it like
SELECT  ORDER BY id DESC LIMIT 5;



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___ ___   __
  /  |/  /_ __/ __/ __ \/ /Egor Egorov
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
   ___/   www.mysql.com




-
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: Nested MySQL Statements

2002-12-14 Thread Adolfo Bello
Not until version 4.1

 -Original Message-
 From: Peter Vertes [mailto:[EMAIL PROTECTED]] 
 Sent: Friday, December 13, 2002 8:43 AM
 To: MySQL Help List (E-mail)
 Subject: Nested MySQL Statements
 
 
 Hello All,
 
 Is it possible to do nested select statements with MySQL 
 ?  Basically I'm trying to display the last 5 rows that got 
 inserted into a table.  My SQL query looks like this:
 
 select * from tablename limit ((select count(*) from 
 tablename) - 5), -1;
 
 In theory it works for me :) but MySQL complains.  Is it 
 possible to do nested queries with MySQL ?  Does anyone have 
 a better way of displaying the last x amount of rows inserted 
 into a table ?  Thanks in advance...
 
 -Pete
 
 Peter Vertes
 Beast Financial Systems
 404 Fifth Avenue
 New York, NY
 10018
 
 -
 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