• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Help with a query

I am building an e-commerce site for motor accesories.  The idea is that the users selects their product and then their car type and model.  I would like to show only products that apply to that model.

My database is structured like:

PRODUCTS TABLE
ProductID (Autonumber)
ProductName (Text)
ProductModels (Text)

CAR MAKES TABLE (eg Ford)
MakeID

CAR MODELS TABLE (eg Escort)
ModelID

So in English I would like to show:

SELECT ALL
FROM PRODUCTS TABLE
WHERE ModelID NOT IN ProductModels

Is this possible?

Thanks

Robert
0
Orroland
Asked:
Orroland
  • 3
  • 2
1 Solution
 
ornicarCommented:
The SQL syntax for this query is:

SELECT * FROM PRODUCTS
WHERE PRODUCTID NOT IN
(SELECT MODELID FROM PRODUCTMODELS)

0
 
nico5038Commented:
Hi ornicar,

I guess you ment:
SELECT * FROM PRODUCTS
WHERE PRODUCTID NOT IN
(SELECT PRODUCTMODELS FROM PRODUCT);

But I get the impression that Richard stores multiple models in one PRODUCTMODELS field...
This would imply that there's a change of database design necessary or a "like *modelid*" construction...

Whats the content of the PRODUCTMODELS field Richard?

Nic;o)
0
 
OrrolandAuthor Commented:
It is a text field with the modelID like 1,2,3,4.  I use check boxes to select the models which apply to the product.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
OrrolandAuthor Commented:
This is giving a Data type mismatch in criteria expression error???

...WHERE modelsubcats.modelsubcatID NOT IN (SELECT productdetails.productdetailmodels FROM productdetails)
0
 
nico5038Commented:
That's because you store the numbers of multiple models, thus the field becomes.... text ;-)

The "general" solution for this is to create a "relation table" like:
tblProductModel with the fields:
ProductID
ModelID
Both making the unique key of the table.

BTW I would also change the CarsModels table into:
CAR MODELS TABLE (eg Escort)
MakeID
ModelID

Thus the relation between Make and Model becomes clear.

Havin created the relation table you can use your checkboxes to insert for each checked model the relation row.

Now the query is simply linking tblProductModel to the Products to show the productname.

Clear ?

Nic;o)
0
 
OrrolandAuthor Commented:
Thanks for the help, this is a great solution.

Robert
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now