Solved

Help with a query

Posted on 2002-04-05
6
166 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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now