MySQL Select minimum/maximum among two (or more) given values

You can use LEAST and GREATEST function to achieve it.

SELECT
    GREATEST(A.date0, B.date0) AS date0,
    LEAST(A.date1, B.date1) AS date1
FROM A, B
WHERE B.x = A.x

Both are described here http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html


I suppose you are looking for:

GREATEST()

and

LEAST()