2

I'm fairly new to SQL Server and would really appreciate some help with this.

I have 4 columns in the same db table each with differing numerical values e.g.

col1 - 8, 6, 7 
col2 - 9, 8, 5
col3 - 12, 15, 2   
col4 - 3, 1, 11

What I would like to do is pick the lowest value from each row and place it within a 5th column such that the result for the above would be:

col5 - 3, 1, 2

I have tried using a select subquery but with no luck. I feel like this should be easy but can't either work it out or find anything similar elsewhere!

Many thanks.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
KnightMair
  • 23
  • 3

1 Answers1

4
UPDATE T
SET    col5 = (SELECT MIN(col)
               FROM   (VALUES (col1),
                              (col2),
                              (col3),
                              (col4)) T(col))  
Martin Smith
  • 438,706
  • 87
  • 741
  • 845