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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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