At 01:22 AM 3/3/2002 , you wrote: >I need to pull a variable number of fields from a table from the last >inputted fields. For example, instead of doing something like > > "SELECT * FROM table" > >I am looking for a way to do something like this(hypothetical, I don't >really know what I should do). > > "SELECT LAST_TEN_FIELDS FROM table" > >which would then pull the most recent ten rows from the table. The reason >why I am asking this mailling list is because I am writing a small program >using PHP and want to get the ten most recent fields. However, since it >is PHP and the script is going to have high traffic, I need to know the >most efficient way of pulling the last ten fields. I know I can do it >through PHP by sorting out the results, but I want the whole thing to be >as streamlined as possible and don't want to have the PHP script in 4 >months chugging away for hours trying to work with the data of 1000 fields >pulled from mySQL. > >This is the structure I have in mind for the table, and this is not 100% >official, but was the way I had initially planned it to go. > >id INT NOT NULL AUTO_INCREMENT, >data VARCHAR(200), >PRIMARY KEY(id) > >The script is going to take a little bit of data, and is only going to >need to display the most recent(top ten probably) results entered, which >is why I need to know if there is an efficient way to do this in mySQL >without causing thousands of chunks of data to have to be handled by PHP. > >All help is appreciated, > >-Eric
Eric, You could try something like: select * from table order by id desc limit 10; The reverse sort will get you there. Just make sure the column is indexed to make it fast, which in your case it is. :) Brent _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.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