Use INNER JOIN with WHERE clauses

0

I'm reassembling a system before in ASP now in PHP already with database loaded and mounted, however I need to do some filters where I need to fetch data from at least 3 different tables and maybe more later (But I'll review this database because it will probably get a lot of server load).

I've mounted this structure, but it looks like my WHERE does not work correctly, actually, I guess I'm not applying correctly. What I did:

SELECT * FROM tb_despesas
INNER JOIN tb_contas ON tb_despesas.id_condominio = tb_contas.id_condominio
INNER JOIN tb_contrato_aluguel ON tb_despesas.id_condominio = tb_contrato_aluguel.id_condominio
WHERE (tb_despesas.id_condominio = 17 AND tb_despesas.mes = 11 AND tb_despesas.ano = 2018)
LIMIT 10

I need to get from the tb_despesas table, the account entries referring to mes 11 and ano 2018 for example referring to the condominium with id 17 . But I need to get for example the value of a field called aluguel that is inside tb_contrato_aluguel, also I need to get the name of the accounts that are in tb_contas .

But this search I do not use the WHERE clause. And it brings thousands of results by way of repeating the values of tb_despesas in other tables.

One way to better exemplify. Currently my tb_expenses has only 2 accounts for this month 11. In other words, I should just search the other tables, the account names and the rent referring to these two accounts and stop here. I applied a limit 10 just to see how many more came back. And it was more or less like the return (I tried to extract by navicat)

Content returned by the query

What would be the correct logic to follow? Apparently I am using WHERE incorrectly, or the INNER JOIN so that I can not apply my conditions.

Thanks in advance.

    
asked by anonymous 23.11.2018 / 15:12

0 answers