0
When using the SQL
below to carry out the count of the number of brokers in a table using INNER JOIN
, works perfectly.
SQL:
SELECT
conta.acesso,
count(corretor.cod) as num_corr
FROM
conta
INNER JOIN corretor
ON conta.id = corretor.cod
where conta.id = '1015'
However, when trying to include the count also of the user number, then everything stops working. See the SQL
down below:
SELECT
conta.acesso,
count(corretor.cod) as num_corr,
count(usuarios.cliente) as num_user
FROM
conta
INNER JOIN corretor
ON conta.id = corretor.cod
INNER JOIN usuarios
ON conta.id = usuarios.cliente
where conta.id = '1015'
In this SQL
just included to count the users table and nothing else works.
Are you sure 'ON account.id = users.client' works? Try without Count first; i.e., SELECT account.access, Count(broker.Cod) as num_corr, users.client as num_user FROM...
– White
@White Sim have done this test before and it works, only on the internet that does not
– Gladison
Want to try it with left Join? I’m just giving ideas...
– White
@White as I do?
– Gladison
use group by?
– Claudio Lopes
What is your database? And your first SQL actually works without the
Group by
?– Matheus Ribeiro
@Matheusribeiro My database is MYSQL and works without GROUP BY
– Gladison
Just replace, INNER JOIN with LEFT JOIN
– White