-3
I have the following SQL
SELECT
`inte`.`int_nome`,
`age`.*,
`con_at`.`con_nome` as consultora_que_atendeu,
`con_ag`.`con_nome` as consultora_que_agendou
FROM (`agendamentos` as age)
JOIN `interessados` as inte ON `inte`.`int_cod`=`age`.`age_cod_interessado`
JOIN `consultoras` as con_at ON `con_at`.`con_cod`=`age`.`age_cod_consultora_atendido`
JOIN `consultoras` as con_ag ON `con_ag`.`con_cod`=`age`.`age_cod_consultora_agendado`
WHERE `inte`.`int_nome` LIKE '%baill%'
GROUP BY `age`.`age_cod`
However, at the time of listing, it searches all the records and prints wrong.
Even if I run the query suggested by our friend Victor:
SELECT DISTINCT
`inte`.`int_nome`,
`age`.*,
`con_at`.`con_nome` as consultora_que_atendeu,
`con_ag`.`con_nome` as consultora_que_agendou
FROM (`agendamentos` as age)
JOIN `interessados` as inte ON `inte`.`int_cod`=`age`.`age_cod_interessado`
JOIN `consultoras` as con_at ON `con_at`.`con_cod`=`age`.`age_cod_consultora_atendido`
JOIN `consultoras` as con_ag ON `con_ag`.`con_cod`=`age`.`age_cod_consultora_agendado`
WHERE `inte`.`int_nome` LIKE '%baill%'
GROUP BY `age`.`age_cod`
What I’m missing in the consultation?
Our dear
SELECT DISTINCT
wouldn’t solve the problem? And the other question is: the other tables no longer have entries from the same USER [As shown in age_cod, 1 and 3] ?– William Aparecido Brandino
Where are the duplicates? All the results are different...
– Jorge B.
Looking at the
age_cod
of its image, we have 1, 3, 5, 6, 7 and 8. Which one is duplicated and why?– Victor Stafusa
I still don’t understand André. What is the problem after all?
– Jorge B.
You do a search for all records containing "Baill", the result seems to be as expected. What do you intend to get?
– Jorge B.
@Jorgeb. the problem is that when displaying, it lists all the records, changing only the name, because the idea is to do a search by name, and return only the result of that name in question, but the name is in another table.
– Sr. André Baill
@But aren’t all those records from that user? It’s just that they seem to be.
– Jorge B.
What you’re trying to get is a list of appointments, a list of interested parties, a list of consultants or a list of what after all? What is it that you call duplicate and what is it that you don’t call duplicate?
– Victor Stafusa
The list I need is the list of schedules of that name in question
– Sr. André Baill
But in my Where, I added: WHERE
inte
.int_nome
LIKE '%baill%' ANDage
.age_cod_interessado
=inte
.int_cod
seems to have resolved– Sr. André Baill
What do I do? Can you close the topic? Apparently you solved the issue using int.int_cod
– Sr. André Baill
Post an answer with the solution.
– Fagner Fonseca