0

i have three tables;

Table one - Reservations +-----------------+-------------+---------------------+---------------------+ | created_id | contract_no | rent_start_date | rent_end_date | +-----------------+-------------+---------------------+---------------------+ | 050316102417112 | 1291 | 2016-03-06 22:00:00 | 2016-03-14 22:00:00 | | 050316102417112 | 8574 | 2016-04-03 10:00:00 | 2016-04-09 20:00:00 | +-----------------+-------------+---------------------+---------------------+

Table two - reservation_customers;

+------------------+---------------+ | created_id | customer_id | +------------------+---------------+ | 050316102417112 | 1 | | 050316102417112 | 2 | +------------------+---------------+

table three - customers

+--------------+-------------------------+--------------------+ | customers_id | customers_firstname | customers_lastname | +--------------+-------------------------+--------------------+ | 1 | john | doe | | 2 | john | doe | +--------------+-------------------------+--------------------+

I need a query that will return contract_no, rent_start_date and rent_end_date from reservations and customers_firstname and customers_lastname from customers using the second table to lookup customers_id.

Any help would be greatly appreciated.

  • 2
    Any help may be appreciated, but if we give you the answer without you trying something, you'll learn nothing. Please post your query attempt in the question. – Tim Biegeleisen Feb 22 '18 at 15:21
  • In the 3rd table, if you change `customers_id` to `customer_id` then you can use a `natural join` and simplify the whole thing, something like: `select * from reservations natural join reservation_customers natural join customers;` – tonypdmtr Feb 22 '18 at 15:45
  • Never knew about natural join, Thanks tonypdmtr. – SQL noob Feb 22 '18 at 17:34

0 Answers0