I need someone to help me with this query


I have a table details_messajeria1 which has two records, and I need collaboration for this query in mysql, since it throws me the two records and should only throw one ... the OR I have already replaced it with the AND and nothing

FROM detalles_mensajeria1 
where mensajero_detalle LIKE 'Luis Muriel' 
    or mensajero_detalle LIKE 'Sebastian Hernandez' 
    and date(fecha_registro) BETWEEN '2018-07-12' and '2018-07-12'
    order by id_detalle

d_detalle id_usu fecha_registro fecha_entrega mensajero_detalle empleado contacto dir_contacto tel_contacto ubicación observación 
1 3 9/07/2018 10:28 12/07/2018 8:00 Luis Muriel Yuliana Ruiz SOS EPS Barrio Versalles 454545 Norte Prueba 
2 3 12/07/2018 10:31 12/07/2018 10:00 Sebastian Hernandez John Ramirez Confamdi Autopista Sur 6841000 Sur
asked by somfyras 13.07.2018 в 14:57

1 answer


If you have a single date it is not necessary to use between, and the detail field to be able to have more than one value you collect it with or but using parenthesis to separate it from the date field.

If you bring a single record as a result, the order is not necessary either because it slows down the query. And in the names it is not necessary to like if you are going to put the exact value of the field.

SELECT * FROM detalles_mensajeria1 
WHERE fecha_registro BETWEEN '2018-07-12' AND '2018-07-12'
      AND (mensajero_detalle = 'Luis Muriel' 
      OR mensajero_detalle = 'Sebastian Hernandez')
answered by 13.07.2018 / 15:48