I have some table structure like this.
table property_day
propday_id | date | property_id | check_in | check_out
------------------------------------------------------
1 | 2017-03-26 | 5 | 0 | 0
2 | 2017-03-27 | 5 | 0 | 0
3 | 2017-03-28 | 5 | 0 | 0
4 | 2017-03-29 | 5 | 0 | 0
table rooms
room_id | name | property_id
----------------------------
1 | Deluxe | 5
2 | Superior | 5
3 | Executive | 5
I want to show all that room with if condition inside query. I show that room with date check in and date check out.
In table property_day
column check_in and check_out is used for indicate guest cannot check in on that date or cannot check out on that date or cannot check in and check out on that date. Value 0 indicate guest can check in or check out but value 1 is indicate guest cannot check in or check out.
This is the if condition :
- If I check in on 2017-03-27 and check out on 2017-03-28 and value in column
check_in
andcheck_out
is 0 on that date I want to show all room inproperty_id
5. - If I check in on 2017-03-27 and check out on 2017-03-28 and value in column
check_in
on 2017-03-27 is 1, I doesn't want to show all room. - If I check in on 2017-03-27 and check out on 2017-03-28 and value in column
check_out
on 2017-03-28 is 1 , I also doesn't want to show all room. - If I check in on 2017-03-27 and check out on 2017-03-29 and value in column
check_in
andcheck_out
in 2017-03-28 is 1, I want to show all room. - If I check in on 2017-03-27 and check out on 2017-03-29 and value in column
check_in
andcheck_out
in 2017-03-28 is 0, I also want to show all room.
This is table structure for condition number 1 :
propday_id | date | property_id | check_in | check_out
------------------------------------------------------
1 | 2017-03-26 | 5 | 0 | 0
2 | 2017-03-27 | 5 | 0 | 0
3 | 2017-03-28 | 5 | 0 | 0
4 | 2017-03-29 | 5 | 0 | 0
This is table structure for condition number 2 :
propday_id | date | property_id | check_in | check_out
------------------------------------------------------
1 | 2017-03-26 | 5 | 0 | 0
2 | 2017-03-27 | 5 | 1 | 0
3 | 2017-03-28 | 5 | 0 | 0
4 | 2017-03-29 | 5 | 0 | 0
This is table structure for condition number 3 :
propday_id | date | property_id | check_in | check_out
------------------------------------------------------
1 | 2017-03-26 | 5 | 0 | 0
2 | 2017-03-27 | 5 | 0 | 0
3 | 2017-03-28 | 5 | 0 | 1
4 | 2017-03-29 | 5 | 0 | 0
This is table structure for condition number 4 :
propday_id | date | property_id | check_in | check_out
------------------------------------------------------
1 | 2017-03-26 | 5 | 0 | 0
2 | 2017-03-27 | 5 | 0 | 0
3 | 2017-03-28 | 5 | 1 | 1
4 | 2017-03-29 | 5 | 0 | 0
This is table structure for condition number 5 :
propday_id | date | property_id | check_in | check_out
------------------------------------------------------
1 | 2017-03-26 | 5 | 0 | 0
2 | 2017-03-27 | 5 | 0 | 0
3 | 2017-03-28 | 5 | 0 | 0
4 | 2017-03-29 | 5 | 0 | 0
This is the query which I already try but doesn't give result what I want.
SELECT p.*, r.*
FROM property_day p
JOIN rooms r on p.property_id = r.property_id
WHERE p.property_id = 5 AND p.check_in = 0 OR p.check_out = 0
That's simple query because I doesn't know to make some query with that if condition.
Please anyone help me to do that. Thank you.