Mysqli select query get statistic from 2 tables

I have two tables, first the table Tickets:

ticketid | gameid
---------+-----------
1        | 6938
2        | 6939
3        | 6940

Second the table Tickets_nums

ticketid | num
---------+-------
1        | 8     
1        | 13     
1        | 27     
1        | 34     
1        | 29     
1        | 45     
1        | 68     
2        | 3     
2        | 11  
2        | 18     
2        | 21     
2        | 27     
2        | 46     
2        | 56     
2        | 70     
3        | 2    
3        | 34     
3        | 44    
3        | 49     
3        | 51     
3        | 56    
3        | 68 

Now i need query to show me (most popular 5 numbers, most least 10 numbers - “Rare Numbers”) from last 50 games (games its by gameid).

But the most least 10 numbers (Rare Numbers) needed check not only from db rows + from total numbers (1 - 70)
And in the end, needed show like this

most popular 5 numbers
----------------------
  14 (178 times)      
  26 (160 times)     
  39 (151 times)     
  44 (143 times)      
  69 (139 times)  

most least 10 numbers
----------------------
  15 (0 times)      
  19 (0 times)     
  21 (6 times)     
  30 (12 times)      
  34 (17 times)   
  38 (29 times)      
  41 (34 times)     
  42 (46 times)     
  52 (51 times)      
  67 (64 times)

Thank you for help!

your query will need the COUNT() aggregate function and an ORDER BY clause

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.