|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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.
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
RE: Tricky SQL question
Nice... of course. Hey nice use of the IN. I always just use it with sub-queries.
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Tricky SQL question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|