rmatthew Posted January 12, 2003 Posted January 12, 2003 I need to get a dataset of the first X records of the database after sorted by a field [RECINDX]. Seems to me that an SQL statement would do the trick - at least I think I shave seen such a function. Can't for the life of me find a reference to it now though. Help :) Thanks in advance. Quote
*Experts* Volte Posted January 12, 2003 *Experts* Posted January 12, 2003 I believe you can use 'SELECT TOP 10 field FROM table WHERE condition' to get the top ten records. If that's not what you're looking for, you could try 'SELECT fields FROM table WHERE condition ORDER BY field DESC LIMIT 10'. So, 'SELECT Name, Age, Address FROM Employees ORDER BY Age DESC LIMIT 5' would get the 5 oldest employees in the table. Quote
rmatthew Posted January 13, 2003 Author Posted January 13, 2003 I am using Access as the database - SELECT * FROM CHRONOLOGY ORDER BY RECINDX DESC LIMIT 1 What I want is the top 1 records from the database (the record holding the highest numerical value in the [RECINDX] field. I need all the columns (unknown to program) so I can't specifically indicate fields I need. However, I did try to select a couple of fields instead of the * and got the same error. Syntax error in ORDER BY clause. by the way - all works without the limit???? Quote
*Experts* Nerseus Posted January 13, 2003 *Experts* Posted January 13, 2003 You should try VolteFace's other method, TOP, as in: SELECT TOP 1 * FROM CHRONOLOGY ORDER BY RECINDX DESC This should work no problem. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.