Using "Top" in SQL statement

Yusuf

Active Member
Joined
Jun 1, 2004
Messages
337
Hi

In my table I have 70,000 records. To copy and paste into Excel, I design a new query for this table, click on SQL view and after SELECT I insert "TOP 65000".
This gives me the first 65,000 records which is perfect to paste in Excel.

Please advise me the best way to get the remainder (i.e. 5000 records) through SQL or if you know of a better way, please let me know.
These I will paste in another sheet in the workbook.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You could sort Ascending on the ID field and grab Top 65000. Then find the Max ID value in that query, and create another query with ID's higher than that value.

Denis
 
Upvote 0
As Denis suggests having a field to order by is critical, you can take the top 65000 sorted ascending on the first query and then the top 4999 sorted descending on the second query.

hth,
Giacomo
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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