1
I have a query that searches for TECHNICAL CALLS and in this research I do some JOINS to bring related information. I need the LIKE to also work for the CLIENT name (which is in another table)
The query I have is this:
SELECT *,
`t1`.`usuario` AS nome_usuario_responsavel,
`t1`.`id_usuario` AS id_usuario_responsavel,
`t3`.`usuario` AS usuario_criador_chamado
FROM (
`usuarios` t1,
`usuarios` t3,
`chamados`
)
INNER JOIN `clientes` ON `chamados`.`fk_cliente_chamado` = `clientes`.`id_cliente`
LEFT JOIN `ativos_cliente` ON `chamados`.`fk_ativo_chamado` = `ativos_cliente`.`id_ativo`
INNER JOIN `categorias` ON `chamados`.`fk_categoria_chamado` = `categorias`.`id_categoria`
INNER JOIN `assuntos` ON `chamados`.`fk_assunto_chamado` = `assuntos`.`id_assunto`
WHERE `t1`.`id_usuario` = `chamados`.`fk_usuario_responsavel_chamado`
AND NOT EXISTS (
SELECT *,
MAX(id_atividade) AS id_ultima_atividade
FROM atividades
WHERE atividades.fk_chamado = chamados.id_chamado
AND (atividades.status = 3 OR atividades.status = 5)
GROUP BY fk_chamado
)
AND `t3`.`id_usuario` = `chamados`.`fk_usuario_criador_chamado`
AND(resumo_chamado LIKE '%teste%' OR texto_chamado LIKE '%teste%' OR id_chamado LIKE '%teste%')
ORDER BY chamados.`data_criacao_chamado` ASC
LIMIT 0,15;
With one or another change your solution fit perfectly.
– EdnaldoNeimeg
@Ednaldoneimeg Feel free to edit my answer the way it was.
– Leonel Sanches da Silva