how to make this query sql

Asked

Viewed 74 times

2

code is PK in both

tabela1: cliente
codigo, nome, municipio

tabela2: notafiscal
codigo, numerodanota, cod_cliente

I want to list give a Count(*) on all notafiscal where cod_client.municipio = 10

how do I run this sql?

2 answers

5


You just need to use the JOIN to link between tables as below:

SELECT COUNT(n.codigo)
  FROM cliente c
       INNER JOIN notafiscal n ON n.cod_cliente = c.codigo
 WHERE c.municipio = 10;

5

Just make a Join between the tables and specify the municipality on WHERE.

SELECT count(*) FROM notafiscal as n 
INNER JOIN clientes as c ON n.cod_cliente =  c.codigo
WHERE c.municipio = 10

Browser other questions tagged

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