code is PK in both
tabela1: cliente
codigo, nome, municipio
tabela2: notafiscal
codigo, numerodanota, cod_cliente
I want to list a count (*) on all notafiscal where cod_client.municipality = 10
How do I run this sql?
code is PK in both
tabela1: cliente
codigo, nome, municipio
tabela2: notafiscal
codigo, numerodanota, cod_cliente
I want to list a count (*) on all notafiscal where cod_client.municipality = 10
How do I run this sql?
You only need to use JOIN
to link between the tables as below:
SELECT COUNT(n.codigo)
FROM cliente c
INNER JOIN notafiscal n ON n.cod_cliente = c.codigo
WHERE c.municipio = 10;
Just do a join between the tables and specify the municipality in WHERE
.
SELECT count(*) FROM notafiscal as n
INNER JOIN clientes as c ON n.cod_cliente = c.codigo
WHERE c.municipio = 10