1
my tables:
agencias (id, nome_agencia, ads -> FK pra tabela de baixo)
ads (id, nome, agencia -> essa é FK pra tabela anterior)
the problem is this: each agency will have an ads in the ads has a main agency
want to make a select displaying agencia_id, agencia_name, ads_id, ads_name_agencia
I tried this, but I don’t know how to "fit" the agency name
SELECT agencias.id as id_agencia, agencias.nome as agencia_nome, ads.id as id_ads, ads.agencia as ads_agencia_id
FROM agencias
INNER JOIN ads
ON agencias.id=ads.agencia
running this query resulted in the following: id_agencia, agencia_nome, id_ads, ads_agencia_id ...... I need tb to return the agency name q is referenced in ads_agencia_id
– Adriano
Just refer to it in select.
ad.nome
, wheread
is the nickname that was set for the table and then the name of the field. You will do so to add all the fields you want.– Pedro Camara Junior