MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
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 May 6th, 2008, 02:07 PM
orbitalx orbitalx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 14 orbitalx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 41 sec
Reputation Power: 0
Exclude options based on already chosen options

I have two tables

Code:
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(11) unsigned | NO   | PRI | NULL    | auto_increment | 
| description | varchar(255)     | NO   |     |         |                | 
+-------------+------------------+------+-----+---------+----------------+


Code:
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(11) unsigned | NO   | PRI | NULL    | auto_increment | 
| description | varchar(255)     | NO   |     |         |                | 
+-------------+------------------+------+-----+---------+----------------+


joined in a many to many relationship by table:

Code:
+------------------+------------------+------+-----+---------+-------+
| Field            | Type             | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+-------+
| lane_id          | int(11) unsigned | NO   | PRI |         |       | 
| configuration_id | int(11) unsigned | NO   | PRI |         |       | 
+------------------+------------------+------+-----+---------+-------+


what I need to do is exclude certain items from the configuration table based on other selected configurations.

for example:

the lanes table holds the following rows:

Code:
+----+-------------+
| id | description |
+----+-------------+
|  1 | Lane 1      | 
|  2 | Lane 2      | 
|  3 | Lane 3      | 
|  4 | Lane 4      | 
+----+-------------+


the configuration table contains:

Code:
+----+------------------+
| id | description      |
+----+------------------+
|  1 | Lanes 2, 3 and 4 | 
|  2 | Lanes 3 and 4    | 
|  3 | Lane 1           | 
|  4 | Lane 2           | 
|  5 | Lane 3           | 
|  6 | Lane 4           | 
+----+------------------+


and the join table contains the appropriate links to create the described relationships.

this is a reservation system, so if, for example, configuration 2 is reserved that would automatically exclude configurations 1, 2, 5 and 6.

I've accomplished this with PHP code, but I feel it would be better and more efficient with SQL.

1. am i right?
2. i'm not an SQL expert so if someone could instruct me on how to do it that would be great.

thanks,
josh

Reply With Quote
  #2  
Old May 7th, 2008, 05:32 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,727 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 19 h 22 m 42 sec
Reputation Power: 848
there are two things i don't understand about your statement of the problem

1. "what I need to do is exclude certain items from the configuration table based on other selected configurations"

what does "exclude from" mean? you want to DELETE rows in the config table?

2. "if, for example, configuration 2 is reserved that would automatically exclude configurations 1, 2, 5 and 6."

assuming configuration 2 is linked via the many-to-many table, what does "exclude from" mean here? you want to SELECT lanes but not include configurations that are not linked?

this confusion probably explains why no one has answered your question so far...
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old May 7th, 2008, 10:44 AM
orbitalx orbitalx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 14 orbitalx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 41 sec
Reputation Power: 0
hmm... I didn't think of that... sorry.

All of the "exclusion" I am talking about is related to SELECT statements. So using the example below, if configuration 2 is reserved (which is handled by another table, but not relevant to the question) I want to be able to perform a select to retrieve open lanes. Since configuration 2 contains lanes 3 and 4, all other configurations that contain one or both of those should not be included in the results of the select.

if that does not make sense let me know.

Thanks,
josh

Reply With Quote
  #4  
Old May 7th, 2008, 02:17 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,727 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 19 h 22 m 42 sec
Reputation Power: 848
Quote:
Originally Posted by orbitalx
I want to be able to perform a select to retrieve open lanes.
Code:
SELECT lanes.id
     , lanes,description 
  FROM lanes
LEFT OUTER
  JOIN reservations
    ON reservations.lane_id = lanes.id
 WHERE reservations.lane_id IS NULL

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Exclude options based on already chosen options


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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