D
D
Denis2015-07-16 15:47:09
MySQL
Denis, 2015-07-16 15:47:09

How to compose SQL query with COUNT?

There are 2 tables in the database: authors and docs with fields (id, name) and (id, title, author).
How to make a query that would display the fields: author - the number of his documents?
if the document does not have an author, then display the number of such documents
Something like:
Vasya 15
Petya 10
Lena 0
null 50

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Koltcov, 2015-07-16
@Norkotik

select au.name, count(docs.id)
from docs 
left join  authors au on au.id = docs.author
group by au.name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question