Skip to content
Advertisement

Getting Distinct Id(FK) by the latest date in SQL Server

I’m currently working on a query where I need to distinct ID based on the latest date created.

Here is my diagram

So my goal is to Distinct ModelId but still show if the LocationId is null or equals to 0 then if LocationId is still the same, Get the Latest DateCreated and show it to the List

Desired output:

Here is my current SQL query:

Advertisement

Answer

Please Try with below code

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement