2
I have a Query where I give a select with INNER JOIN between two tables (contacts and company), I have a field called id_company where I search in the companies table to find the company name, but the id_company field is not mandatory, so it has some contacts with the id_company = 0 field, could solve this with two SELECT, but I don’t think it’s the best way. I saw in some cases the use of IF and ELSE in the query, but I do not have control of this use. the query so far that I am using with error, poís displays only companies that have the id_company field other than 0 (empty):
SELECT c.nome,c.telefone1,c.email,e.nome AS empresa
FROM contatos AS c JOIN empresas AS e WHERE c.id_empresa = e.id
I think of a single query solution, where when the id_company is 0, return the empty or null company name.
he has no company. in the form it is not mandatory to enter a company.
– Diego Braga
See if my answer meets you, I made an online example also to facilitate.
– Caique Romero
Possible duplicate of Left Join or Not Exists
– Sam