0

I'm trying to practice on database design and querying. Given the UseCase: I select a start date and end date, then it will pull down available cars within the set date range. This is my schema: enter image description here

This is my pseudo code:

SELECT vehicle_id FROM reservation WHERE pickup_date AND end_date IS NOT between given start date and end date
edmamerto
  • 7,605
  • 11
  • 42
  • 66
  • show some sample data and the expected result as formatted text. – Vamsi Prabhala May 12 '17 at 15:34
  • @vkp please check my pseudo code – edmamerto May 12 '17 at 15:37
  • pseudo code doesn't help either..it is unclear what you need. – Vamsi Prabhala May 12 '17 at 15:37
  • @vkp i want to select the vehicle_id from reservation WHERE the pick_up date and end_date is not within my start_date and end_date... Let's say start_date is 2017/5/15 end_date is 2017/5/20 – edmamerto May 12 '17 at 15:39
  • Just an FYI... you are selecting from a table that has past, present and future reservations. What if a vehicle has never been reserved, ie. a new vehicle added to the company? Your select will not get that vehicle. – SS_DBA May 12 '17 at 16:01

1 Answers1

1

With the information provided, you can use

select vehicle_id
from reservation
where not (pickup_date<='2017-05-20' and end_date>='2017-05-15')
Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
  • could you also help mie with this http://stackoverflow.com/questions/43942415/sql-best-way-to-iterate-through-returned-results – edmamerto May 12 '17 at 16:31