How to fetch data from two tables in MySQL and count each one? -


how can write in 1 query ?

i have 2 tables 1 likes called (late):

id     name     s_id 1               6 2               6 3       b         5 4       c         8 5               6 6               6 7       c         8 8       c         8 

the other 1 likes called (absent):

id     name     s_id 1               6 2               6 3               6 4               6 5               6 6               6 7       b         5 8       c         8 

i want results table:

where (count late) counts times of late , (count absent) counts time of absents.

name    count late    count absent           4              6  b          1              1  c          3              1 

i tried this:

this didn't work !

select  * (select name, count(*) '# count absent' absent group s_id)  t1  inner join (select name, count(*) '# count late' late   group s_id)  t2 on t1.s_id = t2.s_id ; 

use union of 2 tables: lates , absents... sum number of lates , absents.

try this:

select      sum(tardies) 'total_lates', sum(absences) 'total_absences', name, s_id     ((select         count(*) 'tardies',         0 'absences',         name,         s_id              lates     group         s_id     ) union     (select          0 'tardies',         count(*) 'absences',         name,         s_id              absents      group         s_id     ) ) maintable group s_id order name 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -