Help for this query

1

Good afternoon Personal, I have these two tables that relate to know how many times a user has accessed the system:

And I have this query:

select nome_usuario, count(id_log) as qtde from logs as l left join usuario as u on l.usuario_log = u.id_usuario group by usuario_log order by qtde desc

Today it brings me the result of how many times the user has accessed. And I would like if I can not find records from the log table, assign zero '0' how do I do this?

    
asked by anonymous 14.10.2016 / 22:38

1 answer

1

In%% of the question, change SQL by LEFT JOIN

select u.id_usuario, u.nome_usuario, count(l.id_log) as qtde from logs as l 
        right join usuario as u 
           on l.usuario_log = u.id_usuario 
             group by u.id_usuario, nome_usuario 
              order by qtde desc
    
14.10.2016 / 22:43