insert into table where if not in list

Posted by jim smith on Stack Overflow See other posts from Stack Overflow or by jim smith
Published on 2010-05-09T18:05:02Z Indexed on 2010/05/09 18:08 UTC
Read the original article Hit count: 175

Filed under:

Can anybody help me with the syntax?

insert into history (company,partnumber,price) values ('blah','IFS0090','0.00') if company NOT IN ('blah','blah2','blah3','blah4','blah4') and partnumber='IFS0090';

Background: I have a history table which stores daily company, products and prices. But sometimes a company will remove itself for a few days. Complicating the issue is because I'm only saving daily CHANGES to prices only and not snapshotting the entire days list (the data would be huge) when I display the data the company will still come up for the previous days price. So I need to do something like this, where a 0.00 price means they're no longer there.

© Stack Overflow or respective owner

Related posts about mysql