If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Problem in LEFT JOIN

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-12, 08:30
deb081900 deb081900 is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
Problem in LEFT JOIN

Hi Everybody

I am trying to list records of those rooms which are not booked between two dates. I have 2 tables
roomtable
"Field","Type","Null","Key"
"room_no","varchar(3)","NO","PRI"
"room_type","varchar(10)","NO"
"room_rate","int(4)","NO"
"room_bed","varchar(6)","NO"
bookingtable
"Field","Type","Null","Key"
"book_id","varchar(3)","NO","PRI"
"room_no","varchar(3)","YES"
"date_fro","datetime","YES"
"date_to","datetime","YES"
"no_of_adults","int(3)","YES"
"no_of_child","int(3)","YES"

I tried this query to got my result and I got the list of all rooms which are not booked -
SELECT roomdetail.room_no,room_type,room_bed,room_rate FROM roomdetail LEFT JOIN bookingtable
ON roomdetail.room_no=bookingtable.room_no
WHERE bookingtable.room_no IS NULL;


I tries this also but I got blank output-
SELECT roomdetail.room_no,room_type,room_bed,room_rate FROM roomdetail LEFT JOIN bookingtable
ON roomdetail.room_no=bookingtable.room_no
WHERE DATE(date_fro)>='2012-01-08' AND DATE(date_to)<='2012-01-11' AND bookingtable.room_no IS NULL;

Can any one please help me to solve this problem.

Thank you to all for cooperation.
Regards
Reply With Quote
  #2 (permalink)  
Old 01-09-12, 10:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-09-12, 12:52
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I was going to find the same link that Rudy posted

I draw out Rudy's diagram near the foot of that page almost every time I have to solve a problem like this
__________________
George
Twitter | Blog
Reply With Quote
Reply

Tags
bookingtable, roomtable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On