MySQL Forums
Forum List  »  Newbie

Re: UPDATE with HAVING...
Posted by: Peter Brawley
Date: August 27, 2015 12:17PM

> if I add a WHERE clause, it doesn't affect any register

I guess you mean it does no updates. To debug the query logic, turn it into a Select, eg ...

SELECT t.no_reservacion, t.fecha_fe00, t.observaciones_conciliacion
FROM res_pro_servicios AS t
JOIN (
  SELECT s.no_reservacion
  FROM res_pro_servicios AS s
  JOIN res_reservacion AS r USING (no_reservacion)
  WHERE	r.cliente = 'client' 
    AND r.tipo_producto_cc00 = 'Traslado'  
    AND s.cancelado_cv01 = 'no' 
    AND	s.eliminado_hi01 = 'no' 
    GROUP BY s.no_reservacion
    HAVING Min(s.fecha_fe00) BETWEEN '2015-07-16' AND '2015-07-31'
) as t1 USING(no_reservacion)
WHERE t.cancelado_cv01 = 'no' AND t.eliminado_hi01 = 'no'

run that, if it fetches no rows then try it without the outer Where clause, if that fails run the subquery by itself, if that returns no rows then try it without the Having clause, &c &c till you find where the logic goes awry.

(Query aliases improve readability, and readability facilitates debugging & maintenance.)



Edited 1 time(s). Last edit at 08/27/2015 12:18PM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
August 26, 2015 07:38PM
August 26, 2015 09:39PM
August 27, 2015 11:27AM
Re: UPDATE with HAVING...
August 27, 2015 12:17PM
August 29, 2015 10:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.