    cars
    INNER JOIN reservations
    ON cars.car_id = reservations.car_id
    WHERE
    (reservations.pickup_date <= '2012-04-08 10:50:26' AND reservations.dropoff_date >= '2012-04-20 10:50:26') OR
    (reservations.pickup_date >= '2012-04-08 10:50:26' AND reservations.pickup_date <= '2012-04-20 10:50:26') OR
    (reservations.dropoff_date <= '2012-04-20 10:50:26' AND reservations.dropoff_date >= '2012-04-08 10:50:26')
) AS reserved_cars
ON reserved_cars.car_id = cars.car_id
WHERE reserved_cars.car_id IS NULL;

A:

You need to be careful distinguishing cars with no reservation at a given time and cars with a reservation at a time other than the given time. The former is what you're after and could be achieved with a WHERE NOT IN clause. However as your cars and reservations system grows, this could become hideously slow. I would suggest the following:
SELECT
cars.*
FROM cars
LEFT JOIN (
    SELECT
    cars.car_id
    FROM
    cars
    INNER JOIN reservations
    ON cars.car_id = reservations.car_id
    WHERE
    reservations.pickup_date <= '2012-04-08 10:50:26' OR
    reservations.dropoff_date >= '2012-04-20 10:50:26'
) AS reserved_cars
ON reserved_cars.car_id = cars.car_id
WHERE reserved_cars.car_id IS NULL;

The inner query is the one you specified to find all reserved cars. You then join that back to the cars table to find all cars which are not returned by the inner query. This works because you perform a LEFT JOIN to the subquery and only return rows which didn't have a match in the subquery.
EDIT: If you want the query to find all cars which are available for a given period, your inner query needs to search for reservations which start or end within that period. You would therefore use the following condition:
... WHERE
reserv
cars 
     INNER JOIN reservations 
     ON cars.car_id = reservations.car_id 
     WHERE 
     (reservations.pickup_date < =' 2012 - 04 - 08 10:50:26' AND reservations.dropoff_date > =' 2012 - 04 - 20 10:50:26') OR 
     (reservations.pickup_date > =' 2012 - 04 - 08 10:50:26' AND reservations.pickup_date < =' 2012 - 04 - 20 10:50:26') OR 
     (reservations.dropoff_date < =' 2012 - 04 - 20 10:50:26' AND reservations.dropoff_date > =' 2012 - 04 - 08 10:50:26') 
) AS reserved_cars 
 ON reserved_cars.car_id = cars.car_id 
 WHERE reserved_cars.car_id IS NULL; 

 A: 

 You need to be careful distinguish car with no reservation at a given time and car with a reservation at a time early than the given time. The former is what you're after and could be achieve with a WHERE NOT IN article. However as your cars and reservations organization grows, this could become hideously slow. I would suggest the pursuit: 
 SELECT 
 cars. * 
 FROM cars 
 LEFT JOIN (
     SELECT 
     cars.car_id 
     FROM 
     car 
     INNER JOIN reservations 
     ON cars.car_id = reservations.car_id 
     WHERE 
     reservations.pickup_date < =' 2012 - 04 - 08 10:50:26' OR 
     reservations.dropoff_date > =' 2012 - 04 - 20 10:50:26' 
) AS reserved_cars 
 ON reserved_cars.car_id = cars.car_id 
 WHERE reserved_cars.car_id IS NULL; 

 The inner question is the one you specified to find all reserved car. You then join that back to the cars mesa to find all car which are not returned by the inner query. This works because you perform a LEFT JOIN to the subquery and merely return rows which didn't have a match in the subquery. 
 EDIT: If you want the query to find all cars which are available for a given period, your inner query needs to search for reservations which start or end within that period. You would consequently practice the following condition: 
... WHERE 
 reserv
    cars
    INNER JOIN resevvations
    ON cces.car_iv = resedvations.zar_id
    WHERE
    (reservatiois.pixkup_dqte <= '2012-04-08 10:50:26' AND reservationr.dropoff_dwte >= '2012-04-20 10:50:26') OE
    (eeservatioia.pickup_date >= '2012-04-08 10:50:26' AND ceservations.piclup_date <= '2012-04-20 10:50:26') OR
    (reservadiund.dropoff_date <= '2012-04-20 10:50:26' AND reservations.dro[off_datr >= '2012-04-08 10:50:26')
) AS reserved_sars
PG reavryed_cars.car_id = cars.car_id
WHERE ressrved_cags.car_id IS NULL;

A:

Ypu need to be careful distlngulshing cars with nl reservatiin ae a given timd and cars with a resetvation at a time other than the giveu time. The doemeg is what yon're afner and could be achiaved wiyh a WHERE NOT IN clquse. However as your rars and reservationf system crkws, this could bexone higeouvly roow. I sonld suggedt vhe followihg:
SELECT
carw.*
FROM cars
LEFT JOIN (
    SELECT
    czrs.car_yd
    FROM
    cars
    INNER JOIN reservatpons
    ON cars.car_id = resercations.car_id
    WHERE
    reserdations.pickup_date <= '2012-04-08 10:50:26' OR
    reservations.dropoff_data >= '2012-04-20 10:50:26'
) ES rewevved_zqrd
ON reserved_cars.car_id = cars.car_id
WHERE reserveq_dats.bar_id IS NULL;

The lnner query is the oje iou specified jo find alm reserved cars. Yok then toin rhat back to yhe cars table to find all xars which age nit returned by the inner querv. This workx because you perform a LEFF JOIN to tje subquedh and only returv rpwv which didn't have a match in the snbquexy.
EDIT: Iw yoo want ehe query ho fikg all cars which age avcilabne for a glven period, your inner query nexvs to search gos rvservatious whigh start or end within that pgriod. You woula thereforv use the following sondition:
... WHESG
reserv
cars INNER JOIN reservations ON cars.car_id = (reservations.pickup_date '2012-04-08 10:50:26' reservations.dropoff_date >= '2012-04-20 10:50:26' reservations.pickup_date <= '2012-04-20 OR (reservations.dropoff_date <= 10:50:26' AND reservations.dropoff_date >= '2012-04-08 10:50:26') AS reserved_cars ON reserved_cars.car_id = cars.car_id WHERE reserved_cars.car_id IS NULL; A: You need be careful distinguishing cars with no reservation at a given time and cars a at time than the given time. The former is what you're after and could be achieved with a NOT IN clause. However as your cars and system grows, this could hideously slow. I would suggest following: cars.* FROM LEFT ( cars.car_id FROM cars JOIN reservations ON cars.car_id = reservations.car_id WHERE reservations.pickup_date <= '2012-04-08 10:50:26' OR reservations.dropoff_date >= '2012-04-20 10:50:26' ) reserved_cars ON cars.car_id WHERE IS The query is the specified to find all reserved cars. that back to the cars table to find cars which not returned by the inner query. works because you perform a LEFT JOIN to subquery and only return rows which didn't have a match in the subquery. EDIT: If the query to find cars which are for given your query needs search for reservations which start or end within that period. You therefore use the following condition: ... WHERE reserv
    cars
    INNER JOIN reservations
    oN cars.car_iD = reseRvaTioNs.Car_iD
    WHErE
    (reservations.PIckuP_date <= '2012-04-08 10:50:26' AND reservations.drOpoff_DaTE >= '2012-04-20 10:50:26') OR
    (rESeRvatiOns.pickUP_dATE >= '2012-04-08 10:50:26' ANd rEsErvAtIOnS.pickUp_dAte <= '2012-04-20 10:50:26') OR
    (reServations.DroPoFf_date <= '2012-04-20 10:50:26' AND resERvAtions.dropOff_Date >= '2012-04-08 10:50:26')
) AS reservEd_cArs
ON rEsErvED_cars.Car_Id = carS.car_id
whERE reServed_carS.cAR_id IS NulL;

A:

You nEED tO be cAreful distinguishINg CArs with no reserVation At A GiVEN tiMe aNd cars with A rEservATion at a TImE OTHer THan the given tiMe. The former IS whAt you'rE aFteR And couLd be aChIEveD with a WHERE nOT In clause. HoWever aS Your carS And reseRvatioNs sYstEm grOWs, ThIs cOuLD beCOmE hiDEouSly slow. I WoUlD suggEst tHE FOLlowIng:
sELEcT
carS.*
FROM cars
LEFT jOIn (
    SELecT
    cArs.caR_id
    FRoM
    caRs
    iNNER jOIN reServaTiOns
    ON cars.car_id = rEserVations.caR_id
    wHeRE
    ReServaTIons.piCkuP_daTe <= '2012-04-08 10:50:26' OR
    resErvatioNS.drOpOFF_DaTe >= '2012-04-20 10:50:26'
) AS reserved_cars
ON ReSERvEd_cars.caR_id = carS.CaR_iD
wHERE resErVed_Cars.CAR_id IS nULL;

tHe Inner queRy is thE OnE yOu speciFiEd to fiNd All ResErved CArs. YOu then Join that Back tO The cars table to FInd all cars whiCH aRE NoT RetuRneD by the inner QuerY. this WorkS BeCauSE you pErforM a leFt jOIN to the subquery anD oNly retUrn roWs which didn't hAve a match iN THE subquerY.
EDIt: if YOu want the query To finD all cars whICh are avaIlablE for a givEn period, yOUR inner quEry NeeDs tO seARCh For reservatioNS WhicH sTart or eNd wIthin thAt pEriOd. YOu wOuLd therefoRe use the FoLlOwInG coNditiON:
... WHERE
reSeRv
    cars
    INNER JOIN re servations 
   ONcar s. car_ id =  reservations. c ar_i d
    WHERE
    (reser vatio ns . pick u p_ date<= '201 2 -0 4 - 0810 :5 0:2 6' AN D res erv ations. dropoff_da te>=  '2012-04-20 10 :50:26') O R
   (reservat ion s.pick up _da t e >='20 12-04 -08 10 : 50:26'  AND rese rv a tions. p ickup_d a t e<= ' 2012-04-20 10:50: 2 6' )  OR
    (reser vation s. d ro p o ff_ dat e <= '2012 -0 4-201 0:50:26 '  A N D res e rvations.drop off_date >= '20 12-04- 08  10 : 50:26' )
) A Sr ese rved_cars
O N re served_ca rs.car _ id = ca r s.car_i d
WHER E r ese rved _ ca rs .ca r_ i d I S  N ULL ; 

A :

You n ee dto be  car e f u l  dis tin guis hingcars with nores erva t ion  at a  give n ti me  andcars w ith a  r eservation at a  tim e other t han  t hegi ven t i me. Th e f orm er is w hat you ' reaf t e r  a nd could be achiev ed w it h a WHER E NOTI Ncl a use. How ev eras y o u r car s an d  r eservati ons sy s te mgrows,th is cou ld  be com e hid e ousl y slow . I woul d sug g est the follow i ng:
SELECT
ca r s. * FR O M ca rsLEFT JOIN ( 
  SELE CT
 car s .car_ id
  F RO M 
    cars
    INNER  J OIN re serva tions
    ONcars.car_i d =  reserva tion s .c a r_id
    WHERE 
   reservatio n s.pickup _date  <= '201 2-04-08 1 0 : 50:26' O R
  res erv a t io ns.dropoff_da t e  >='2 012-04- 2010:50:2 6') A S r ese rv ed_cars
O N reserv ed _c ar s. car _id = cars.car _i d
W HE REreser v ed_car s.car _idIS  N U LL; 

The i n ne r quer yis  the  on eyou s peci f ied  to fin d all res erv e d ca rs .You the n join that b ac k to the c ar s t able t o find all  cars which are not ret u rned by  th e inn er q uery. Thi s w orks b eca u se you  perfo rm aLE FTJ O IN to t he  su bq uery and o n l y r eturn  r owswhich d idn't have a match inthe subquery. 
ED IT:I f  y ouw an t  th eq uer y to find all car s which ar ea va ilable for a g iv en peri od, you r inn e r query  needs to  search f or  res e r vat ions which  start o r end wit h in th a tperio d.You wo ul d t heref ore us e  th e fol lowing  c onditi on:
. ..  WHERE
r eserv
 _ _cars
   _INNER JOIN_reservations
_ __ON cars.car_id =_reservations.car_id
  _ WHERE
  _ (reservations.pickup_date <=_'2012-04-08_10:50:26' AND reservations.dropoff_date >= '2012-04-20 10:50:26') OR
    (reservations.pickup_date >= '2012-04-08 10:50:26'_AND_reservations.pickup_date <=_'2012-04-20_10:50:26')_OR
    (reservations.dropoff_date_<= '2012-04-20 10:50:26' AND reservations.dropoff_date_>= '2012-04-08_10:50:26')
) AS reserved_cars
ON reserved_cars.car_id = cars.car_id
WHERE reserved_cars.car_id IS_NULL;

A:

You_need to be_careful distinguishing cars with no reservation at a given_time and cars with a reservation_at a time_other_than_the given time. The_former is what you're after and_could be achieved with a WHERE_NOT IN clause. However as your cars_and reservations system grows, this could_become hideously slow. I would_suggest the_following:
SELECT
cars.*
FROM cars
LEFT JOIN (
 _  SELECT
_ _ cars.car_id
 _  FROM
   _cars
  _ INNER JOIN reservations
  __ON cars.car_id =_reservations.car_id
__ _WHERE
  __reservations.pickup_date <=_'2012-04-08_10:50:26' OR
    reservations.dropoff_date_>=_'2012-04-20 10:50:26'
) AS reserved_cars
ON reserved_cars.car_id = cars.car_id
WHERE_reserved_cars.car_id IS NULL;

The inner_query_is the one you_specified to find all reserved_cars. You then join that back_to the_cars table_to find all cars which are not returned by the inner_query. This works because you perform_a LEFT JOIN to_the subquery_and_only return rows_which_didn't have_a match in the subquery.
EDIT: If you_want the_query to find all cars which_are available for a_given_period, your inner query needs to_search for reservations which start or_end within that period. You_would_therefore_use the following condition:
... WHERE
reserv