Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase 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 Codewalkers Forums Sponsor:
  #1  
Old March 25th, 2004, 05:01 PM
reedsmith reedsmith is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 8 reedsmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Tricky SQL question

I have 2 tables

table products:
-----------------
productID
productName

table options:
-----------------
optionID
productID
optionName

I need to select a product that has a specific option combination. for example:

"SELECT p.productID FROM products p, options o WHERE p.productID = o.productID and o.optionName = 'red' AND o.optionName = 'small'

This returns the correct records but it also will return products that have more than these options. It will return a product that has the following options. 'red', 'small', 'tshirt'. How can I get just the products that have exactly the same option combination (no more, no less).

Thanks

Reply With Quote
  #2  
Old March 26th, 2004, 08:18 AM
icandothat's Avatar
icandothat icandothat is offline
Super Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,563 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 17 m 20 sec
Reputation Power: 3
RE: Tricky SQL question

You should include data types and a somewhat more descriptive example. If you could please provide three rows from each table, what your looking for and what comes up that you dont want I think I can give you an answer.

Reply With Quote
  #3  
Old March 27th, 2004, 11:49 PM
-vertigo- -vertigo- is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Louth, Lincolnshire
Posts: 314 -vertigo- User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 24 sec
Reputation Power: 2
RE: Tricky SQL question

SELECT p.productID
FROM products p, options o
WHERE p.productID = o.productID
and o.optionName in ['red','small']

I am not 100% sure of the syntax of the 'in' statement, so check the manual just to make sure what the syntax is.

Reply With Quote
  #4  
Old March 28th, 2004, 07:08 AM
icandothat's Avatar
icandothat icandothat is offline
Super Moderator
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 1,563 icandothat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 17 m 20 sec
Reputation Power: 3
RE: Tricky SQL question

Nice... of course. Hey nice use of the IN. I always just use it with sub-queries.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Tricky SQL question


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 1 hosted by Hostway
Stay green...Green IT