I'm using MySQL and InnoDB,
I have a table reserver
with 2 columns : idReservation
and idChambre
I have a table reservation
and a table chambre
Now I want my query to return every "chambre.id" who is not between my dateDebut and dateFin.
Below is my actual query :
SELECT cre.id
FROM reserver AS rer
INNER JOIN reservation AS ron
ON rer.idReservation = ron.id
RIGHT JOIN chambre AS cre
ON rer.idChambre = cre.id
WHERE (ron.dateFin < ?
OR ron.dateDebut > ?
OR (ron.dateFin = NULL AND ron.dateDebut = NULL))
My problem is that my return value only contains chambre when the id of the chambre is already in reserver.
My second problem is that "RIGHT JOIN" add every chambre to my query, but what I want is only chambre as : "ron.dateFin < ? OR ron.dateDebut > ?" or chambre who are not already on linked to reserver.
EDIT : here's some sample rows :
reserver :
id |idReservation | idChambre
---+--------------+----------
0 | 1 | 1
chambre :
id | idCategorie
---+------------
1 | 1
2 | 2
reservation :
id | date | dateDebut | dateFin
---+------------+------------+---------
1 | 03/04/2015 | 01/04/2015 | 06/04/2015
2 | 05/04/2015 | 08/04/2015 | 12/04/2015
I want my query to return id 1 and 2 for chambre but all I get actually is 1
P.S : Sorry, english is not my native language but stackexchange is such an amazing website.
chambre.id
. What exactly do you want? It's better if you provide sample rows and what happens (vs. what you want).1
and2
SQL FiddleWHERE
clause you did not show.