SQL QUERY - TOP # of RECORDS

rmatthew

Well-known member
Joined
Dec 30, 2002
Messages
115
Location
Texas
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. Cant for the life of me find a reference to it now though. Help :)

Thanks in advance.
 
I believe you can use SELECT TOP 10 field FROM table WHERE condition
to get the top ten records. If thats not what youre 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.
 
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 cant 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????
 
You should try VolteFaces other method, TOP, as in:
Code:
SELECT TOP 1 * FROM CHRONOLOGY ORDER BY RECINDX DESC

This should work no problem.

-Nerseus
 
Back
Top