0

I have following table

id column1 column2 column3 column4
1 2000 1000 4000 3000
2 6000 7000 8000 1000
3 8000 10000 7000 4000

I want to get max and min values from multiple columns in single row using mysql query

So in short I need following output

max_value min_value
10000 1000

1 Answer 1

4

Use the scalar LEAST and GREATEST functions:

SELECT id, GREATEST(column1, column2, column3, column4) AS max_value,
           LEAST(column1, column2, column3, column4) AS min_value
FROM yourTable;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.