Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 29th, 2003, 10:50 AM
jakuza's Avatar
jakuza jakuza is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 65 jakuza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 52 sec
Reputation Power: 6
Question Avoiding partial extraction while joining

Hi there.

This is the situation:
Table A with a set of bookable resources (rooms, cars... it doesn't matter what).
Table B with reservations with an obvious foreign key to A and 2 timestamp for starttime and endtime of the reservation.

We need to extract all available resources in a given time interval.

Lazy way: query over B to get all unavailable resources and a second query over A to get all the other resources.

Smart way: one only query over A joined to B.

But... I'm not so smart! I don't find a way to extract all available resources that don't figure in the table B (read: never-booked-before resources).

Have someone out there an idea to show please?
Thanks in advance. Bye

Reply With Quote
  #2  
Old June 29th, 2003, 11:20 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,762 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 4 h 29 m 45 sec
Reputation Power: 37
Code:
select * from a
where booking not in (select booking 
 from b 
where localtime between starttime and endtime)

Reply With Quote
  #3  
Old June 29th, 2003, 12:01 PM
jakuza's Avatar
jakuza jakuza is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 65 jakuza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 52 sec
Reputation Power: 6
In MySQL subqueries will only be supported since version 4.1 on.
Even if we know that version is about to come, I intended to create a general query useful over every DB engine. Have you any other idea?

Reply With Quote
  #4  
Old June 29th, 2003, 02:51 PM
kylnas's Avatar
kylnas kylnas is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Italy
Posts: 8 kylnas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by jakuza
In MySQL subqueries will only be supported since version 4.1 on.
Even if we know that version is about to come, I intended to create a general query useful over every DB engine. Have you any other idea?


I hope it's ok (i tried it in a visual basic project and it seems to work... )

SELECT a.* FROM A a LEFT JOIN B b ON (a.booking=b.booking) WHERE b.starttime IS NULL OR localtime NOT BETWEEN b.starttime AND b.endtime

Honestly i don't know why the "b.starttime IS NULL" clause permits the query to work...but it doesn't matter, if it really works, doesn't it?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Avoiding partial extraction while joining


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway