I have a table which I get sampling values: AeroSamples
id time temperature pressure humidity
I sample the values at a 5 minute period. Before inserting a new row into the table, I check if the last row's temperature, pressure and humidity values are same with current values. If so, I do not want to add a new row. Else A new record could be added.
I do this like that:
SELECT temperature, pressure, humidity FROM AeroSamples ORDER BY id DESC LIMIT 1
When I get the last values, I compare three fields with current values which is the way I do not like:
if($row["temperature"] !== $curTemp || $row["pressure"] !== $curPres || $row["humidity"] !== $curHumi)
{
$db->prepare("INSERT INTO AeroSamples (temperature, pressure, humidity) VALUES(:t,:p,:h)");
...
}
How can I do this SQL only?
Does ON DUPLICATE KEY UPDATE ...
help me? I do not think so. Because I am not sure if it is valid for multiple fields at a time.