How to update table with max function and flag should be marked as 'M' only one row.
Attachments: Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.
It is updating 2 two rows but i want only one row should be update.
SET flag = 'm'
FROM test t
INNER JOIN (
SELECT companyid, MAX(shipment_count) as shipment_count
GROUP BY companyid
ON t.shipment_count = m.shipment_count
You will need to use row_number and a CTE to do this
with cte as
( select row_number() over (order by shipment_count desc) as rn, * from test )
update cte set flag = 'm' where rn = 1
15 People are following this question.
Issue while upgrading SQL Server 2012 express to SQL Server 2016 express edition.
sharepoint error connecting to active node
For sql server 2016 memory optimized databases is row versioning ON by default.
What is the most optimal use of the IN-clause from C# code
SQL Server 2016 Query Store behavior