How to get maximum and minimum values ​​in one query?

I use MySQL, and I am looking for a way to get global maximum and minimum values ​​(for the whole table) from two columns (e.g., posxand posy) using only one query.

+5
source share
4 answers

Plain:

SELECT MIN(posx), MIN(posy), MAX(posx), MAX(posy) FROM table
+17
source
SELECT
    MIN(colx) AS minimum,
    MAX(colx) AS maximum,
    MIN(coly) AS minimum,
    MAX(coly) AS maximum
FROM table
+4
source

It really is not harder than it sounds.

SELECT MIN(posx), MAX(posx), MIN(posy), MAX(posy)
FROM yourtable
+4
source
 select max(posx), min(posy) from table
+2
source

All Articles