Du ønsker måske at bruge GREATEST()
funktion:
SELECT GREATEST(field1, field2);
Hvis du vil have det absolutte maksimum fra alle rækkerne, kan du bruge følgende:
SELECT GREATEST(MAX(field1), MAX(field2));
Eksempel 1:
SELECT GREATEST(1, 2);
+----------------+
| GREATEST(1, 2) |
+----------------+
| 2 |
+----------------+
1 row in set (0.00 sec)
Eksempel 2:
CREATE TABLE a (a int, b int);
INSERT INTO a VALUES (1, 1);
INSERT INTO a VALUES (2, 1);
INSERT INTO a VALUES (3, 1);
INSERT INTO a VALUES (1, 2);
INSERT INTO a VALUES (1, 4);
SELECT GREATEST(MAX(a), MAX(b)) FROM a;
+--------------------------+
| GREATEST(MAX(a), MAX(b)) |
+--------------------------+
| 4 |
+--------------------------+
1 row in set (0.02 sec)