Hi,
I have tried the select top 1000 rows and found out that it does not show the latest inserted/ added rows in any table. Do I have to fetch rows via latest date? please suggest any sample code to do this. Thanks!
April 14, 2020 at 9:04 pm
unless you have some way to order them in insertion order, you can't. You'd need a column that's either an incrementing identity column or a datetime field with a default of the insertion date.
April 14, 2020 at 10:00 pm
so, I looked at the table again and it has Date column, so will it work if I query based on the date column? if you have any sample query please share.
April 14, 2020 at 10:38 pm
So, you are asking us a question when we have no knowledge of the table or the data that is being stored in the table. So, a shot in the dark: it depends on what data is stored in that date column.
DateCreated? DateModified? DateOfBirth? DateOfNextScheduledDentistVisit? ....
If it contains the date the row was created, you can do something like this
SELECT TOP (1000)
col1, col2, ...
FROM tbl
ORDER BY <DateColumn> DESC
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
April 15, 2020 at 2:51 am
You should read and understand the documentation on any functionality before you try to use it.
https://docs.microsoft.com/en-us/sql/t-sql/queries/top-transact-sql?view=sql-server-ver15
--Jeff Moden
Change is inevitable... Change for the better is not.
April 16, 2020 at 4:46 pm
Thanks, this did the trick, It was date inserted or created column
SELECT TOP (1000)
col1, col2, ...
FROM tbl
ORDER BY <DateColumn> DESC
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply