How to know the total of real estate and the total of photos in an SQL with two INNER JOIN?

Asked

Viewed 39 times

0

I have the following SQL INNER JOIN and would like to know how I can get the total of REAL ESTATE and also the total of PHOTOS, I have already used COUNT(immovel.id) AS TOTAL to know the total of real estate but the result does not match the reality:

select
clientes.id,
clientes.nome, 
clientes.status,
clientes.cliente,
clientes.tipo,
clientes.disponibilidade,
imoveis.id,
imoveis.cod,
imoveis.status,
imoveis.vvenda, 
fotos.cod
from clientes
inner join imoveis on clientes.cliente = imoveis.cod
inner join fotos on fotos.cod = imoveis.id
where
imoveis.status='2'
AND clientes.status='2' 
AND imoveis.vvenda < clientes.disponibilidade
AND imoveis.vvenda <> '0'
AND clientes.cliente = '$cliente'
AND imoveis.cod = '$cliente'
GROUP BY clientes.id

Somebody help me?

  • SQL questions are more easily answered if you say (1) the columns and table types used, (2) give examples of what the result should be (output). In the case of Join it is also useful to know which are the foreign keys (Foreign Keys), i.e., which columns of a table refer to a column of another table.

  • 1

    try COUNT(distinct imoveis.id) AS TOTALIMOVEIS, COUNT(distinct FOTOS.COD) AS TOTALFOTOS , but as @Edu said SQL responses go through knowing the model

  • This question and the other question (http://answall.com/q/118412/129) may be converted into one?

No answers

Browser other questions tagged

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