I have statistics gathered each 6 hours in the database each saved with a timestamp. Then I have array of timestamp in my code. I need to select a value from database for each value in my array of timestamp and that row will have the closest higher or equal timestamp than is in the array.
To illustrate: Table with data
Id Timestamp Value
1 1400000027 10
2 1400000035 15
3 1400000043 20
4 1400000044 21
5 1400000048 30
6 1400000060 35
The array contains following timestamps:
[1400000020, 1400000024, 1400000035, 1400000050]
The rows I need to get from the database based on the input array are:
Id Timestamp Value
1 1400000027 10
1 1400000027 10
2 1400000035 15
6 1400000060 35
Is there a simple way to do this in one query? And the best solution would be in doctrine, since I am using Symfony 2 and Doctrine.