Merge 2 different tables and display content by sorting by number of views (highest to lowest) of the two joins in MySQL

4

Considering that I have 2 tables in the DB, "news" and "news", each with its own fields:

IsitpossibletomakeaSELECTinthetwotablesatthesametimesothatIgetthetop4valuesofthefields"impressions" (NEWS table) and "clicks" (NEWS table), the two combined? >

The expected result would be this (sorting from highest to lowest):

  • Wrong (15 views)
  • Hello (9 views)
  • Medium (6 views)
  • Good (5 views)
  • asked by anonymous 30.12.2015 / 21:32

    1 answer

    4
    select * from 
    (select titulo, impressoes as visualizacoes
    from 
    noticias 
    union ALL
    select titulo, cliques as visualizacoes
    from cliques) result order by result.visualizacoes desc
    limit 0,4
    

    Result:

    Fiddle

        
    30.12.2015 / 22:00