MySQL Forums
Forum List  »  Newbie

Re: UPDATE with HAVING...
Posted by: Marco Rios
Date: August 29, 2015 10:19AM

Peter Brawley Wrote:
-------------------------------------------------------
> > 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.)

Fine! thanks a lot, I really wad doing something wrong, It is now working.
You are right, my code is now easier to understand.

Thanks in advance for your valuable help.

Acer LENOVO G450
CPU: Pentium(R) Dual-Core CPU T4400 @ 2.20GHz × 2
RAM: 4GB
Graphics: Intel GM45
OS: UBUNTU 18.04.4 LTS 64bits
GNOME 3.28.2
--
Best regards
Marco
Mexico City, Mexico

Options: ReplyQuote


Subject
Written By
Posted
August 26, 2015 07:38PM
August 26, 2015 09:39PM
August 27, 2015 11:27AM
August 27, 2015 12:17PM
Re: UPDATE with HAVING...
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.