php - Mysql Match date -


i have table called promotions

already inserted data:

columns             value `startdate`         15-03-2014 00:00:00 `enddate`           30-05-2014 00:00:00 `promotion_for`     1 (product_id) 

new query insert data

columns             value `startdate`         15-03-2014 00:00:00 `enddate`           30-05-2014 00:00:00 `promotion_for`     1 (product_id) 

i don't want insert new promotion if promotion running in same product during insert date.

no idea how generate mysql query it.

first add unique key promotions:

alter table `promotions`  add unique index(`startdate`,`enddate`,`promotion_for`);  

then:

insert `promotions` ( `startdate`,`enddate`,`promotion_for`) values ('15-03-2014 00:00:00', '30-05-2014 00:00:00', '1')  on duplicate key     update `startdate`='15-03-2014 00:00:00', `enddate`='30-05-2014 00:00:00', `promotion_for` = '1'; 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -