SQL help

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,772
I'm still a novice when it comes to writing SQL's, and I'm really struggling with a particular project.


We use an Excel add-in that contains an SQL editor to query our core database. This means that if a query returns more than 65,000 rows, the data is incomplete.

In order to only return the relevant data, I want to restrict the records I query in a particular table to just the 2 most recent records.

If anyone could point me in the right direction or suggest a suitable website, I'd be extremely grateful.

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
To get the last 2 records, sort Descending on the table's ID and run a Top records query. As an example, this will select the Top 2 records from a sample table --

Code:
SELECT TOP 2 tblDateTest.DateID, tblDateTest.TestDate
FROM tblDateTest
ORDER BY tblDateTest.DateID DESC;

Denis
 
Upvote 0

Forum statistics

Threads
1,225,358
Messages
6,184,497
Members
453,236
Latest member
Siams

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