0
I have 3 tables in the database:
tbl_cupom_generated:
id_cupom | nome
------ -----
40 João
60 Maria
tbl_coupon:
id | desconto | id_estabelecimento
---- -------- -------
40 50% de desconto 1
60 20% de desconto 2
tbl_establishment:
id | nome
--- ------
1 Agência X
2 Agência Y
I would like to integrate the tables in order to relate the id_coupon of tbl_coupon generated with the discount of tbl_coupon and the name of tbl_establishment, in order to give SELECT in the name, discount and name of the establishment. I wrote a code with INNER Joins, but it is not successful. What can I fix?
SELECT nome, tbl_cupom.desconto, tbl_estabelecimento.nome
FROM tbl_cupom_gerado, tbl_cupom
INNER JOIN tbl_cupom ON tbl_cupom.id = tbl_cupom_gerado.id_cupom
INNER JOIN tbl_estabelecimento ON tbl_estabelecimento.id = tbl_cupom.id_estabelecimento
But are you making a mistake? Or just not returning any data? The only thing "wrong" is that you are not specifying from which table you want the first "name". A tip, create alias for tables for example: From tbl_coupon as c.
– Paulo Vinícius
I wasn’t returning any data, but I was able to correct it. I specified the table data as you commented, and removed tbl_coupon from FROM leaving only tbl_cupom_generated. Thanks for the help
– Gabriel AMXCOM