Append values to MySQL column and delete old values Engine MySQL 5.6.37 

I have a table with the following structure:

CREATE TABLE `multi` (
  `unitid` varchar(16) NOT NULL,
  `value` varchar(21) DEFAULT NULL,
  `date_time` timestamp NULL DEFAULT NULL,
   PRIMARY KEY (`unitid`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


When I perform inserts on this table, I would like to append the 'value' column with new values seperated by  a delimiter, and then only keep the latest 3 values at any point. 

I am doing it this way using PHP PDO  - 

 $sql = "INSERT INTO multi (unitid, value, date_time)
VALUES (?,?,?) ON DUPLICATE KEY UPDATE presence_value= CONCAT(value, ?), 
date_time = ?;";
$stmt = $db-&gt;prepare($sql);
$stmt-&gt;execute([$unit, $value, $time, ','.$value, $time]);


Whenever this php is called, it will keep appending the value column with new values separated by comma. 

I then perform a CRON job every few minutes to alter the value column and keep the latest 3 values.

Is there a better way to do this? I would like to eliminate the CRON job altogether. Can I do this using triggers?
First, you can use the VALUES() syntax to update. No need to send parameters twice:

$sql = "
    INSERT INTO multi
        (unitid, value, date_time)
    VALUES
        (?,?,?)
    ON DUPLICATE KEY UPDATE
        presence_value = CONCAT(value, VALUES(value)), 
        date_time = VALUES(date_time);
";


To keep only the last three, you can use some string functions:

        presence_value = CONCAT_WS(','                                -- separator
                                   SUBSTRING_INDEX(value, ',', -2),   -- last two 
                                   VALUES(value)),                    -- new one 


The code becomes:

$sql = "
    INSERT INTO multi
        (unitid, value, date_time)
    VALUES
        (?,?,?)
    ON DUPLICATE KEY UPDATE
        presence_value = CONCAT_WS(','                                -- separator
                                   SUBSTRING_INDEX(value, ',', -2),   -- last two 
                                   VALUES(value)),                    -- new one 
        date_time = VALUES(date_time);
";
$stmt = $db-&gt;prepare($sql);
$stmt-&gt;execute([$unit, $value, $time]);



No CRON jobs, no events, no triggers needed.
You need to make sure that that the 3 concatenated values will not exceed the 21 characters combined or increase the size of the column.