zero_ZX Posted December 8, 2011 Share Posted December 8, 2011 Hi, So I'm trying to make a car rental project, and I need to show cars of a specific type, available in a specific period. I'm currently using this query: SELECT * FROM car, reservations WHERE car.car_id = reservations.car AND car.type = 1 AND reservations.reserved_from >= "2011-12-22" AND reservations.reserved_to <= "2012-12-20"; So this returns all the cars of the type 1 reserved in 2011-12-22 - 2012-12-20 period. So know that I know which cars are unavailable, how would you go ahead and pick out what's left? Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/ Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 So you want to return the cars that aren't reserved? Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295659 Share on other sites More sharing options...
zero_ZX Posted December 8, 2011 Author Share Posted December 8, 2011 Yep, but only once, as one specific car only can be rented out once, so no duplicate entries Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295662 Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 In the database, is the default value for reserved_from none? If so you should just be able to do WHERE reservations.reserved_from = "" Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295664 Share on other sites More sharing options...
zero_ZX Posted December 8, 2011 Author Share Posted December 8, 2011 No, the field is not null, and doesn't have a default value. Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295665 Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 So what is it set to when the car is no longer reserved? Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295672 Share on other sites More sharing options...
zero_ZX Posted December 8, 2011 Author Share Posted December 8, 2011 It was just a reservation. There are multiples rows with the same car but different dates. Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295687 Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 Oh, I see. Is the reserved_to/from fields DATE/DATETIME? If yes you can try WHERE reservations.reserved_to < CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295698 Share on other sites More sharing options...
zero_ZX Posted December 8, 2011 Author Share Posted December 8, 2011 The plan is to check in the future, not just today :/ Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295708 Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 Hmm. Without knowing how you wish to use the information I can't offer a better suggestion. But if it's available today, it should also be available in the future no? Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295712 Share on other sites More sharing options...
zero_ZX Posted December 8, 2011 Author Share Posted December 8, 2011 You put like you want car type 1, and it must be available from date_start to date_end Then it should show all cars of type 1, not reserved in period date_start and date_end. Quote Link to comment https://forums.phpfreaks.com/topic/252735-mysql-search-across-multiple-tables/#findComment-1295717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.