Good morning, I have a problem when it comes to making a query, since it does not return the desired result.
The conditions for the consultations are marked by the user with a form similar to this one:
And this is the scheme of the tables:
and finally, the query I'm trying to use:
SELECT DISTINCT m.Nombre_IUPAC,m.Nombre_Tradicional, r.Ruta, m.Imagen_Molecula, m.Codigo_Producto, m.idMolecula
FROM molecula as m
join ruta as r
ON r.idRuta=m.Ruta_Imagen_Molecula
join molecula_has_organismo_productor as mo
on m.idMolecula=mo.Molecula_idMolecula
join organismo_productor as op
on op.idOrganismo_Productor=mo.Organismo_Productor_idOrganismo_Productor
left join carbono as c
on c.Molecula_idMolecula=m.idMolecula
left join tipo_carbono as tc
on tc.idTipo_Carbono=c.Tipo_Carbono_idTipo_Carbono
join actividad_biologica_has_molecula as abm
on abm.molecula_idMolecula=m.idMolecula
join actividad_biologica as ab
on ab.idActividad_Biologica=abm.Actividad_Biologica_idActividad_Biologica
where m.Nombre_Tradicional like ''
or m.Nombre_IUPAC like ''
or m.Codigo_Producto like ''
or op.Nombre like ''
or m.Peso_Molecular BETWEEN '' AND ''
or tc.Carbono = ''
or c.Desplazamiento BETWEEN '' AND ''
or ab.Nombre in ('Ipsum','Flamatoria')
group by m.idMolecula
having count(1)=2
The problem with all this consultation is that there are records that do not come out when I want to filter the options of biological activity, but they appear if I remove the relationship that I have with the producer organization. I will be frank, I will not handle the join with so many tables, and the problem will surely be there.