SQL Max vs Latest Record

Hi

I have a SQL query where I want to show information in the last record entered on a field called [Machine number] rather than just the Maximum.
Is this possible?
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
John TsioumprisConnect With a Mentor Software & Systems EngineerCommented:
You need some kind of indication that marks the latest entry per machine ...either a timestamp or a sequential recordID....from there you take the max of them to get the associated latest entry...
0
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
Do u have a date column like when the record is inserted?

Or do you know how that record is the latest one.
0
 
Pawan KumarDatabase ExpertCommented:
If yes you have a date or some id column you can use below to get the Latest Machine Number row. You can replace the * with the column names you want.

SELECT TOP 1 *
FROM yourtableName
ORDER BY dateColumn DESC

or

SELECT TOP 1 *
FROM yourtableName
ORDER BY IdColumn DESC /*Some Integer primary Key*/
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thank you. There is a Date column, which I will use. I appreciate the advice from both of you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.