MySQL Forums
Forum List  »  Newbie

Querying table to see if date range clashes with database date range
Posted by: Roger Novelo
Date: April 04, 2019 01:18AM

Hello,

I need you all's expertise. Basically I'm trying to create a car reservation system. My idea is for the customer to input a date range. From date / To date, This in turn will query two tables (carlist and booking) where the carlist is basically all the vehicles in the lot, and the booking already reserved dates for the vehicle. I need to output the list of cars that do not overlap with reserved dates.

Eg:

This is information already in the databases.

table carlist c , booking b

SELECT c.License_no, c.Make, c.Model, b.From_date, b.To_date FROM carlist c, booking b where c.License_no = b.License_no;

c.License_no | c.Make | c.Model | b.From_date | b.To_date

C-1234 | Honda | Civic | 2019-04-05 | 2019-04-09
C-2334 | Mitsubishi | Galant | N/A | N/A
C-4443 | Nissan | Sentra | 2019-04-23 | 2019-04-27

Then my date inputs to check would be something like... from: 2019-04-20, to: 2019-04-25

At this point I need the part of the query to check the date range inputs against the database date range and output something like..

License_No | Make | Model
C-1234 | Honda | Civic
C-2334 | Mitsubishi | Galant

because the input dates clash with the Nissan dates

Can anybody help me create the MySQL query to make this happen, I would very much appreciate it.

Options: ReplyQuote


Subject
Written By
Posted
Querying table to see if date range clashes with database date range
April 04, 2019 01:18AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.