943,649 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 2761
  • MySQL RSS
Apr 25th, 2005
0

Troubled with Rewriting Subquery as JOINs

Expand Post »
Please, please, help me out in rewriting my sub-query to some kind of JOIN for earlier MySQL version:


The query should retrive any availble rooms from the database


MY ATTEMPTED SUB-QUERY:

Select *
From Room R
Where R.room_no
NOT
IN(
Select B.room_no
From R.room_no = B.room_no
And R.room_type = ‘single’
And B.arrival_date = ‘2005-03-23’
And B.departure_date = ‘2005-04-30’
)


My ATTEMPTED JOIN: not working correctly

Select *
From room R, booking B
Where R.room_no = B.room_no
And R.room_type = ‘single’
And B.arrivel_date = ‘2005-04-23’
And B.departure_date=’2005-04-30’

I welcome any better ideaa or comments.


For your information, this are the TABLES in my database:

Room (room_ no, room_ type, price)
Guest (guest_ no, Fname, Sname, address)
Booking (room_no, guest_no, Fname, Sname, arrival_date,
departure_date, emp_no, user_name, password)
Employee (emp_no, Fname, Sname, user_name, password)
Admin (admin_no, Fname, Lname, user_name, password)


I hope to hear from you soon folks. Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsgnews is offline Offline
8 posts
since Apr 2005
Apr 26th, 2005
0

Re: Troubled with Rewriting Subquery as JOINs

Hi

I would add a 'group by' and add the date to the return so you know what date the return is telling you about. But without knowing the column types I am a bit lost as to how I would do the grouping / ordering! What I mean is that you can pull stuff from table booking and add it to each row returned from table room!

MySQL Syntax (Toggle Plain Text)
  1. SELECT
  2. *
  3. FROM room AS r
  4. LEFT JOIN booking AS b
  5. ON ( r.room_no = b.room_no AND r.room_type = 'single' )
  6. WHERE
  7. b.arrivel_date = '2005-04-23'
  8. AND
  9. b.departure_date = '2005-04-30'

demo
Reputation Points: 10
Solved Threads: 2
Newbie Poster
demo is offline Offline
18 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: URGENT: UBBThreads MySQL database merge
Next Thread in MySQL Forum Timeline: secure access to customer portal page?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC