Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL unisce 2 set di risultati escludendo i record nel primo

Prova

SELECT id, crp, starts_on
FROM tbl_crps
NATURAL JOIN (SELECT crp, MAX(id) id
              FROM tbl_crps
              WHERE starts_on < CURRENT_DATE
              GROUP BY crp) x
UNION ALL
SELECT id, crp, starts_on
FROM tbl_crps
NATURAL JOIN (SELECT crp, MAX(id) id
              FROM tbl_crps
              GROUP BY crp
              HAVING MIN(starts_on) >= CURRENT_DATE) x;

violino