Solved Using SQL to select only 2nd record

How about select Top 2 and sort descending? Then just process the first record.
 
Yes, ech TOP needs its own ORDER BY.
I already wrote that above.
 
If there is an ID field,

Code:
SELECT TOP 1 T.X, T.Y, T.Z FROM TBL1 AS T
WHERE T.ID NOT IN
(SELECT TOP 1 TS.ID FROM TBL1 AS TS ORDER BY TS.ID)
ORDER BY T.ID ;

This ONLY works if (a) you have a key field like ID and (b) your "TOP" criteria was based on sorting on the ID field.

As was pointed out, you cannot have a "TOP" unless you specify an ordering. Otherwise, TOP has no meaning. More precisely, TOP without an order is essentially a random selection since tables are unordered sets.

If the ordering is based on a no-dups field, the above should do the trick. Basically, get rid of the first record that would be found by the TOP modifier and take the next top.

EDIT: If you are doing your ordering on a data field that isn't a primary key, the question becomes ambiguous if the ordering field is not unique.
EDIT 2: Fixed placement of ORDER BY clauses.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom