I have 2 tables - Equipments and Reservations.
Equipment table looks like this:
ID NAME
1 termo
2 hydro
3 force
4 hammer
Reservation table:
ID EQUIPMENT_ID START END
1 2 25.3.2015 26.3.2015
2 2 26.3.2015 27.3.2015
3 1 28.3.2015 29.3.2015
4 3 27.3.2015 28.3.2015
I want to be able to print all equipments and the nearest date in the future from the current date for each equipment.
So the output looks like this when the date is (24.3.2015):
NAME START END
termo 28.3.2015 29.3.2015
hydro 25.3.2015 26.3.2015
force 27.3.2015 28.3.2015
hammer null null
I tried some nested queries, not functioning. To find the nearest future date from the current date is that i know
SELECT start FROM reservations WHERE start > NOW() ORDER BY start LIMIT 1
but i dont know how to join the tables to find the nearest date for each equipment. Any ideas?