Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Selecione o valor máximo de duas tabelas


Resuma a união de duas consultas de resumo, algo assim.
SELECT user_id, 
       MAX(user_date) user_date
  FROM
   (
     SELECT user_id, 
            MAX(last_contact) user_date 
       FROM emails_sent
      GROUP BY user_id
   UNION ALL
     SELECT whatever_user_id_column user_id, 
            MAX(whatever_date_column) user_date 
       FROM whatever_table
      GROUP BY user_id
   )a
GROUP BY user_id