Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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.

Posted

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????

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...