Analyzing your SQL
you can see that it wasn’t very clear to you how to make relationships in JOINS
, recommend you read here: What is the difference between INNER JOIN and OUTER JOIN?
Leaving for your trouble, I’d do something like this:
SELECT * FROM cliente as c
INNER JOIN cliente_contato as ct ON ct.id_cliente = c.id
INNER JOIN cliente_ip as cip ON cip.id_cliente = c.id
INNER JOIN cliente_mac as mac ON mac.id_cliente = c.id
INNER JOIN cliente_pppoe as pppoe ON pppoe.id_cliente = c.id
This way is linked all tables by your id_cliente
ensuring data integrity, if any of these tables are not required in your result you can exchange INNER
for LEFT
.
Leaving for your research:
WHERE ct.nome LIKE '%{$pesquisa}%'
OR ct.telefone LIKE '%{$pesquisa}%'
OR cip.detalhes LIKE '%{$pesquisa}%'
OR mac.detalhes LIKE '%{$pesquisa}%'
OR pppoe.usuario LIKE '%{$pesquisa}%'
OR c.nome LIKE '%{$pesquisa}%'
That way it will bring the result if only one of the conditions meet.
Final Code
SELECT * FROM cliente as c
INNER JOIN cliente_contato as ct ON ct.id_cliente = c.id
INNER JOIN cliente_ip as cip ON cip.id_cliente = c.id
INNER JOIN cliente_mac as mac ON mac.id_cliente = c.id
INNER JOIN cliente_pppoe as pppoe ON pppoe.id_cliente = c.id
WHERE ct.nome LIKE '%{$pesquisa}%'
OR ct.telefone LIKE '%{$pesquisa}%'
OR cip.detalhes LIKE '%{$pesquisa}%'
OR mac.detalhes LIKE '%{$pesquisa}%'
OR pppoe.usuario LIKE '%{$pesquisa}%'
OR c.nome LIKE '%{$pesquisa}%'
The research is
OR
orAND
?– Guilherme Nascimento
The query is OR, if it is within the table, any of them.. returns, if it does not return empty... but the search field is one.
– Sr. André Baill