MySQL Forums
Forum List  »  General

Complex Query - Optimization
Posted by: Robert Hawke
Date: November 01, 2004 11:44AM

Hi! Here is a brief description of my problem:

I have a table which displays the occupancy of office rooms.

It has the following layout:
name | room | day | hour

Here is a data example:
Robert | A5 | 1 | 8
Dan | A5 | 1 | 8
Robert | A6 | 1 | 9
Dan | A6 | 1 | 9

The first record means that Robert uses this room every 1st Day of the Week (Monday) from 8 to 9 o clock

Now I want to see which rooms are available (not used) at a certain day at a certain hour.

I already have a working solution, but it is deadly slow (takes about 10 seconds to evaluate), since the table contains about 2000 records.
Has anybody got an idea how to solve this more efficently?

SELECT DISTINCT room from room_schedule WHERE room not in (SELECT DISTINCT room FROM room_schedule WHERE day = 1 and hour = 8) ORDER BY room

Note: This query only works with MySQL 4.1 since older versions do not support Sub-Queries.

Thanx for some ideas!

Robert

Options: ReplyQuote


Subject
Written By
Posted
Complex Query - Optimization
November 01, 2004 11:44AM
November 02, 2004 09:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.