
Given the following table in SQL Server

What is the best way to write the query that yields the following result (i.e. one that yields the final column – a column containing the minium values out of Col1, Col2, and Col 3 for each row)?

Using CROSS APPLY! like shown in below code
SELECT ID, Col1, Col2, Col3, MinValue
FROM YourTable
CROSS APPLY (SELECT MIN(d) AS MinValue FROM (VALUES (Col1), (Col2), (Col3)) AS a(d)) A
Leave a comment