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

Como posso obter dados de duas tabelas


Usando colunas fictícias para contabilizar as diferentes estruturas e adicionar uma união para juntá-las:
SELECT * FROM (
    (SELECT article_id, title, article , NULL as cloudinary_id, NULL as url, user_id, created_on, 'article' as table_name  FROM article)
    UNION ALL
    (SELECT gif_id, title, NULL as article, cloudinary_id , url,  user_id, created_on , 'gif' as table_name  FROM gif)
) results
ORDER BY created_on ASC