Max value amongst 4 columns in a row.

Posted by KandadaBoggu on Stack Overflow See other posts from Stack Overflow or by KandadaBoggu
Published on 2010-04-16T22:53:39Z Indexed on 2010/04/16 23:03 UTC
Read the original article Hit count: 207

Filed under:
|

I have test_scores table with following fields:

Table schema:

  id (number)
  score1  (number)
  score2  (number)
  score3  (number)
  score4  (number)

Sample data:

id score1 score2 score3 score4
1  10     05      30    50
2  05     15      10    00
3  25     10      05    15

Expected result set:

id col_name col_value
1  score4   50
2  score2   15
3  score1   25

What is a good SQL for this?(I am using MySQL.)

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql