I am using php
to make a SELECT
of the database, however I need to select
check if one of the fields has been filled in and, if so, execute a new SELECT
of another table.
Basically the idea is that I have a coupon table:
tabela: cadastro_cupom
id | nome_cupom | valor_cupom | id_cliente
When the id_cliente
field is populated, I need to get its name from another table:
tabela: cadastro_cliente
id | nome_cliente | idade_cliente | etc...
I'm 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 can not get the results and I do not see any errors.