5
I’m using the php
to make a SELECT
of the database, but I need the select
check that one of the fields has been filled in and, if yes, run a new SELECT
from another table.
Basically the idea is that I have a coupon table:
tabela: cadastro_cupom
id | nome_cupom | valor_cupom | id_cliente
When the field id_cliente
is filled in, I need to get his name from another table:
tabela: cadastro_cliente
id | nome_cliente | idade_cliente | etc...
I am currently using this SQL:
SELECT id, nome_cupom, valor_cupom, id_cliente
FROM cadastro_cupom
CASE WHEN id_cliente IS NOT NULL THEN
SELECT b.nome_cliente
FROM cadastro_cupom a, cadastro_cliente b
WHERE a.id_cliente = b.id
END
But I’m not getting the results and also I don’t see any errors.
Use the
left join
just asSELECT a.*, b.* FROM cadastro_cupom a LEFT JOIN cadastro_cliente b ON a.id_cliente = b.id
would not solve ?– William Novak
@Williamnovak seems to have solved yes. I’m new to SQL and PHP so I didn’t know about this function.. If you could come up with a response to the matter, I would appreciate it :)
– CMCarlo