Posts

Showing posts with the label Extract the row values of which another field has maximum value

SQL Server, Extract the row values of which another field has maximum value

Image
Hi Guys! One of the typical requests that who writes in SQL is faced with is extract the row values of which another field has maximum value. While extracting the maximum from a column is simple, this general case is less so. The important thing is to recognize these cases . Today we will see how to solve them. Extract the row values of which another field has maximum value Suppose having a table inventory_movements that contain a list of movements. The fields in this table are: the product, the entry date of the movement and the value of the product on the date of entry of the movement. This below is the table structure Create Table inventory_movement (id int identity(1,1) primary key , Product varchar (40), Datemov datetime , ValueMov float ) To better understand the concept let’s do an example I insert some data into the table: Insert into inventory_movements (Product, ValueMov, Datemov) values ( 'ACME Bird Seeds v1' , 1.21, ...