Naveh Naveh - 2 months ago 10
MySQL Question

How to get max value of a column from two tables

I have one table named 'posts' and one table named 'threads'. Both have the column called 'total_id' which is an integer.
Now, how to get from those two tables the 1 highest value (max) in the 'total_id' column? (MySQL)

Answer

You can get it as follows:

SELECT Greatest(
          (SELECT Max(total_id) FROM posts),
          (SELECT Max(total_id) FROM threads)
       )