[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Help with a query

Posted on 2002-04-05
6
Medium Priority
?
174 Views
Last Modified: 2006-11-17
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
Comment
Question by:Orroland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ornicar
ID: 6920808
The SQL syntax for this query is:

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

0
 
LVL 54

Expert Comment

by:nico5038
ID: 6920824
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
 

Author Comment

by:Orroland
ID: 6920831
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:Orroland
ID: 6920883
This is giving a Data type mismatch in criteria expression error???

...WHERE modelsubcats.modelsubcatID NOT IN (SELECT productdetails.productdetailmodels FROM productdetails)
0
 
LVL 54

Accepted Solution

by:
nico5038 earned 200 total points
ID: 6920909
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
 

Author Comment

by:Orroland
ID: 6920969
Thanks for the help, this is a great solution.

Robert
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question