There is a table:
event |id |timestamp --------------------- event1|001|21-03-15 event2|001|22-03-15 event1|002|23-03-15 event2|002|24-03-15
What should be a request to display the result:
id |event1 |event2 | ---------------------- 001|21-03-15|22-03-15| 002|23-03-15|24-03-15|
I think you first need to make a selection of unique id
:
SELECT id FROM test GROUP BY id;
And then something like this:
SELECT timestamp
FROM ...
WHERE id IN (SELECT id FROM test GROUP BY id) AND event='event1';
Events are known in advance ('event1', 'event2')
.
If there are recurring events under one id, with different or the same timestamp, add columns to the result, for example:
id |event1 |event2 |event1 |event2 | ---------------------------------------- 001|21-03-15|22-03-15|23-03-15|23-03-15| 002|23-03-15|24-03-15|NULL |NULL |