Access SQL TOP n ORDER BY issue

aaronward

Board Regular
Joined
Aug 2, 2006
Messages
165
I have a a table with primary key being [Account Number]. I am trying to order all my accounts by their priority and then return the next account to be worked (the top account). i use the sql like:

Code:
SELECT  TOP 1 [Account Number]
FROM LiveData
WHERE WorkingRep Is Null
ORDER BY Priority ASC;

However, upon using the order by clause, ALL account numbers are returned. Likewise, i can take out the order by clause it works, but i am unable to work my first priorty, then 2nd priorty, etc. Any ideas?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I tried a very similar query in Access 2007 and found it to work just fine.

Have you tried using a nested sub-query:
SELECT TOP 1 [Account Number]
FROM (select [Account number] from LiveData
WHERE WorkingRep Is Null
ORDER BY Priority ASC) as SubQuery;
 
Upvote 0
Steven, that works great! All my books tell me the other query 'should' have worked as I desired, so it doesnt surprise me you were able to get it to work. However, I am curious as to why it doesnt work for me...however, I will move on with the great solution you have suggested, thanks again!
 
Upvote 0
While I have most certainly moved on from this problem, I really do appreciate the information! Access sure is its on 'beast'. Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top