Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL - how to select maximum value of a column, but also select other columns?

$
0
0

My SQL code is below. I have a table 'Document Instance' joined to various other tables. In my system, a new document instance is created every time a new version of the document is released or someone makes a changes to settings. As a result, there will be multiple instances of the same document version.

I have my code working fine for displaying everything, but I only want to display the Min instance for each document version. So as an example, I will have DocumentId 1 which will have multiple versions 1. 1.1 1.2 etc and each version may have multiple instances. I only want the minimum instance for each version of each document.

I am not too experienced with joins and can't get my head round what I have researched in context to my query.

SQL
SELECTDocument.Name,DocumentInstance.IdDocumentInstanceId,DocumentInstance.Version,...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>