-2
Good afternoon, I have a table of clients and plans that have keys between them, and I need to list all clients and show the name of the plans if the client has any linked plan. Clients q have no linked plan appear with the repeat plan of the previous line.
SELECT clientes.id, clientes.chave, clientes.chave_plano, clientes.chave_sistema, planos.chave AS c_plano, planos.nome AS nome_plano FROM clientes JOIN planos ON clientes.chave_plano = planos.chave OR clientes.chave_plano IS NULL;
Can you help me ?
insert image description here
If you want to list all clients and when you don’t have a plan associated the plan data is NULL then use LEFT OUTER JOIN and not INNER JOIN.
– anonimo
Thanks for your help, but LEFT OUTER JOIN also repeated the name of the plan, I put an image with LEFT in my question
– Suporte
Post the definition of the involved tables together with the indication of the primary and foreign keys. Take this condition
OR clientes.chave_plano IS NULL
.– anonimo
I cloned the images in the question. if remove OR clients.chave_plano IS NULL does not list clients without linked plans
– Suporte
Here at Sopt posting images is not a suitable practice. See: Manual on how NOT to ask questions.
– anonimo
With INNER JOIN you will certainly not list, with LEFT OUTER JOIN you will certainly list.
– anonimo
Now it worked, thanks. Thanks for the manual, I’m new here :D
– Suporte