I have a table like so:
id | subscriber_id | var_name | var_value | created
1 | 35 | last_name | Smith | [TIMESTAMP]
2 | 35 | city | New York | [TIMESTAMP]
3 | 35 | city | Boston | [TIMESTAMP]
In this case, let's say that the row where var_value=Boston
has a later timestamp than the var_value=New York
row, and thus we will be selecting the Boston
row.
I have tried something like this, but it sometimes says something about non-aggregate column grouping.
SELECT
var_name, var_value
FROM
subscriber_vars
WHERE
subscriber = ?
GROUP BY subscriber
ORDER BY
created DESC
So in this case, an expected output would be:
[
'last_name' => 'Smith'
'city' => 'Boston'
]