Is it possible to perform an innerJoin to know the quantity of the second table?

Asked

Viewed 21 times

0

I am making a database with two entities, where entity "A" is a category, and in each category contains several items, in the case entity "B", what I need to know is: it is possible to bring information from entity A with the amount of items in table B?

SELECT tabelaA.*, tabelaB.count(*) FROM tabelaA INNER JOIN tabelaB 
WHERE tabelaA.id = tabelaB.id
GROUP BY tabelaA.id;

1 answer

1


I do not understand very well but I think this is it. use alias for table name is cleaner.

SELECT A.*, COUNT(B.categoria) as ContarCategoria FROM tabelaA A INNER JOIN tabela B  ON A.id = B.id GROUP BY A.id;
  • That’s right, but I had another problem, but that’s not urgent answer, when table B has none row it returns no value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.