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
Post a Comment