

SQL Selection of the maximum based on a major minor schema
source link: https://www.codesd.com/item/sql-selection-of-the-maximum-based-on-a-major-minor-schema.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SQL Selection of the maximum based on a major minor schema
I am trying to create a query that will select a DISTINCT line, select using a revision Minor / Major scheme. Below is an example table:
Serial Number | RevMajor | RevMinor
-----------------------------------
AQ155 | 1 | 1
AQ155 | 1 | 2
AQ155 | 1 | 1
AQ155 | 1 | 7
AQ155 | 2 | 1 <---------
JR2709 | 1 | 7
JR2709 | 2 | 2 <---------
How can I write a query in T-SQL 2008 that will select only the two highlighted lines, the "Newest Revision"?
Thanks in advance!
You could
select * from (
select *, row_number() over (partition by [Serial Number] order by RevMajor desc, RevMinor desc) VersionRank
from table
) T
where VersionRank = 1
Related Articles
Selection of the maximum based on the last Boolean value FALSE [T-SQL]
SQL selection with the condition
SQL - Selection in a table based on the corresponding values given in another table
SQL Join only the maximum line puzzle
SQL to query the maximum number of items available for a specific period (reservation system)
The SQL query gets the maximum value on the date of occurrence
In Oracle SQL, what is the maximum number of AND clauses in a query?
SQL SELECT Returning the same value twice in GridView
SQL Select from the table twice
SQL query with the maximum value of the child table
Oracle SQL: Select Minimum and Maximum from different rows
SQL - Selection of the part of a string
SQL returns only the maximum date for each ID
KendoUI ComboBox selection of the Datasource-based option
Recommend
-
4
Introduction The first time I heard and noticed schema back in 2005, I completely ignored it because I’m comfortable using dbo as my default schema. But, as time went by, I decided to understand and implement it in my...
-
7
Filtering SQL Compare to a Schema One of the things that numerous clients have some to Redgate about is allowing a team of...
-
9
Minor, Major and Overarching Design Principles Published July 1, 2021 - 0 Comments Design principles are guidelin...
-
12
V2EX › 数据库 Bytebase - 一款新的开源 SQL 审核和 Schema 管理工具 tianzhou · 12 小时 46 分...
-
5
面试官:Minor GC、Major GC、Full GC 区别?我竟然答不上来。。 作者:javacodegeeks 来源:http://www.importnew.com/15820.html
-
8
Introduction The first time I heard and noticed schema back in 2005, I completely ignored it because I’m comfortable using dbo as my default schema. But, as time went by, I decided to understand and implement it in my...
-
13
Interactive Piano Reference to All Major & Minor ScalesInteractive Piano Reference to All Major & Minor Scales💫 Here's a visual & interactive reference for a...
-
4
Apple iPhone 14 Pro Max hands-on: A major and minor upgrade at the same time You know the saying “if it ain’t broke, don’t fix it”? Apple doesn’t believe in that. Even though th...
-
3
iPhone 14 Pro Review: Major Minor Upgrades
-
9
At Stack Overflow, our environment has multiple implementations of a largely – but not 100% – identical schema. (By “schema,” I mostly mean the set of tables within a database.) I sometimes need to retrieve or update data across a large number of...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK