0
Hello, I have a table of projects that contains status, responsible and other columns. I’m doing the following consultation,
  SELECT status,COUNT(status) AS Total 
  FROM projetos 
  WHERE responsavel='Teste' 
  GROUP BY status ORDER BY status;
Then returns only the status that that responsavel has and I would need it to return all status but with the COUNT(status) with zero value.
This way the table comes this way:
+-----------+-------+
| status    | total |
+-----------+-------+
| Cancelado |     1 |
+-----------+-------+
And I need it to come from the following:
+-------------+-------+
| status      | total |
+-------------+-------+
| Cancelado   |     1 |
| Finalizado  |     0 |
| Em processo |     0 |
| Parado      |     0 |
| Atrasado    |     0 |
+-------------+-------+
The responsible named test has only one project in which the status is as Canceled.
The query with LEFT OUTER JOIN does exactly what you want.
– anonimo
But it’s just a single table I have, as it would look ?
– Wallace
So how does your DBMS know what are all possible status? Or does this list exist only in your head?
– anonimo
It is relative, a user can come and register a project with any status he wants, but in the beginning they are those of the example.
– Wallace