1
votes

I am trying to figure out how I can use sql to select rows from an table where column1 value is the greatest? In other words, let's say I have a table Table1 with 10 columns. I need to compare column1 to column2 and column3 and column4 and column5, and select where column1 have the greatest value. For example, here is my table below, and column1 has the greatest value in this example.

column1 column2 column3 column4 column5 column6 column7 column8
299        2       56     8      16       9      18       33
1

1 Answers

0
votes

Use greatest():

where column1 > greatest(column2, column3, column4, column5, column6, column7, column8)