MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2012, 03:58 AM
vishalonne vishalonne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 16 vishalonne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 5 sec
Reputation Power: 0
Query returns record which is not needed

Hi All
I am trying to write a Hotel Room Booking System using Java and MySQL.

I want to select those records only which are available between a range of dates.
Suppose 112 is book for 5 days say from 22/11/2012 to 27/11/2012, then this record of room no. 112 must not be diaplayed for these dates
22/11/2012
23/11/2012
24/11/2012
25/11/2012
26/11/2012
27/11/2012
Whether I select date range from 24/11/2012 to 26/11/2012 or from 21/11/2012 to 25/11/2012 or from 25/11/2012 to 27/11/2012. I my sql query is not performing what I want
SELECT roomdetail.room_no, room_type, room_bed, room_rate FROM roomdetail LEFT JOIN bookingtable ON roomdetail.room_no=bookingtable.room_no AND DATE(date_fro) >= 'strdtver1' AND DATE(date_to) <= 'strdtver2' WHERE bookingtable.room_no IS NULL;

Above query displays the room 112 which is already booked if I select dates range given in example.
Table structure -
roomdetail
Field Type Null Key Default Extra
room_no varchar(3) NO PRI NULL
room_type varchar(10) NO NULL
room_rate int(4) NO NULL
room_bed varchar(6) NO NULL

bookingtable
Field Type Null Key Default Extra
book_id int(3) NO PRI None
room_no varchar(3) YES NULL
date_fro datetime YES NULL
date_to datetime YES NULL
no_of_day int(3) YES NULL
I trying to do this by this way but not successfull

I need guidance and support pls help

Reply With Quote
  #2  
Old November 20th, 2012, 04:30 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
Are you able to echo the actual query that MySQL sees?

And can you clarify what exactly it is that you're after? For instance, would you like to see available reservation periods between given dates, or only rooms that are completely available for the entire date range?

It seems that one or other of date_to and no_of_days is redundant. And why is date_fro datetime? Do you rent rooms by the hour? ;-)

Last edited by cafelatte : November 20th, 2012 at 04:35 AM.

Reply With Quote
  #3  
Old November 20th, 2012, 04:58 AM
vishalonne vishalonne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 16 vishalonne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 5 sec
Reputation Power: 0
Quote:
Originally Posted by cafelatte
Are you able to echo the actual query that MySQL sees?

And can you clarify what exactly it is that you're after? For instance, would you like to see available reservation periods between given dates, or only rooms that are completely available for the entire date range?

It seems that one or other of date_to and no_of_days is redundant. And why is date_fro datetime? Do you rent rooms by the hour? ;-)

Thank you for considerating my problem

YES I can see only those rooms which are avaliable if I mention date 22/11/2012 to 27/11/2012
But if I mention dates eg.
from 24/11/2012 to 26/11/2012 or from 21/11/2012 to 25/11/2012 or from 25/11/2012 to 27/11/2012
This display the Room No. 112 also which should not because it book from 22nd to 27th.

Reply With Quote
  #4  
Old November 20th, 2012, 06:03 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
This response doesn't address any of my questions and, without site of your actual data, is in any case meaningless!

Consider providing proper DDLs AND corresponding desired result set so that we can replicate your problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Query returns record which is not needed

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap