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

Seleziona righe separate da due tabelle, ordina per data

Utilizzo di colonne fittizie per tenere conto delle diverse strutture, un'unione per unirle e un genitore seleziona per gestire l'ordinamento:

SELECT * FROM (
    (SELECT foo.id, NULL AS title, NULL AS body, foo.downloads, foo.views, foo.created FROM foo)
    UNION ALL
    (SELECT NULL AS id, bar.title, bar.body, NULL AS downloads, NULL AS views, bar.created FROM bar)
) results
ORDER BY created ASC