SQL command for MySQL ?

SQL command for MySQL ?

am 17.03.2010 09:07:25 von Stephane MAGAND

Hi

i am debutant in SQL and i am search to know if it's possible:


My SQL requets:


UPDATE Table_Logs_Summary SET
mails_recus=(mails_recus+1),mail_rbl=(mail_rbl+1) WHERE dom_id=4 AND
Date_Start="2010-03-16 06:00:00" AND Date_End="2010-03-16 06:59:59";


I wan't know if they have a optimised sql requets for said if the
WHERE don't exist, he create it !
(if he don't have dom_id=4 AND Date_Start="2010-03-16 06:00:00" AND
Date_End="2010-03-16 06:59:59" he
create by in INSERT) (a IF NO EXIST ?)


thanks
Stephane

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: SQL command for MySQL ?

am 17.03.2010 21:20:50 von Chris W

I'm not 100% sure I understand what you are wanting but if I do, the
INSERT ... ON DUPLICATE KEY UPDATE Syntax detailed here....
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.h tml

Will probably do what you want. For it to work you would have to have a
unique key on the three fields (dom_id, Date_Start and Date_End).

So your query would look like this

INSERT INTO Table_Logs_Summary
(mails_recus ,mail_rbl, dom_id, Date_Start, Date_End)
VALUES
(1, 1, 4, '2010-03-16 06:00:00', '2010-03-16 06:59:59')
ON DUPLICATE KEY UPDATE
mails_recus=(mails_recus+1),mail_rbl=(mail_rbl+1)

Chris W

Stephane MAGAND wrote:
> Hi
>
> i am debutant in SQL and i am search to know if it's possible:
>
>
> My SQL requets:
>
>
> UPDATE Table_Logs_Summary SET
> mails_recus=(mails_recus+1),mail_rbl=(mail_rbl+1) WHERE dom_id=4 AND
> Date_Start="2010-03-16 06:00:00" AND Date_End="2010-03-16 06:59:59";
>
>
> I wan't know if they have a optimised sql requets for said if the
> WHERE don't exist, he create it !
> (if he don't have dom_id=4 AND Date_Start="2010-03-16 06:00:00" AND
> Date_End="2010-03-16 06:59:59" he
> create by in INSERT) (a IF NO EXIST ?)
>
>
> thanks
> Stephane
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org