I have a MySQL table of the form...
record timestamp
1 2014-07-10
2 2014-07-10
1 2014-07-11
2 2014-07-11
1 2014-07-12
2 2014-07-12
...and I want to query this in such a way that I return a set of the form...
record 1st time 2nd time 3rd time
1 2014-07-10 2014-07-11 2014-07-12
2 2014-07-10 2014-07-11 2014-07-12
...
I'm comfortable using MAX()
and a subquery to achieve the most-recent timestamp, but this seems more suited to returning an iterable SQL object. For instance, if I could create the above with something like...
SELECT record, timestamp[0] AS "1st time", timestamp[1] AS "2nd time", timestamp[2] AS "3rd time"
...that would be great. Is this something PIVOT()
could be used for?