Select where a value present

Posted by Roy on Stack Overflow See other posts from Stack Overflow or by Roy
Published on 2011-02-18T10:27:34Z Indexed on 2012/11/21 11:03 UTC
Read the original article Hit count: 155

Filed under:
|
|
|
|

First a database example:

id, product_id, cat, name, value
--------------------------------
1,1,Algemeen,Processor,2 Ghz
2,1,Algemeen,Geheugen,4 GB

3,2,Algemeen,Processor,3 Ghz
4,2,Algemeen,Geheugen,4 GB

5,3,Beeldscherm,Inch,22"
6,3,Beeldscherm,Kleur,Zwart
7,3,Algemeen,Geheugen,3 GB
8,3,Algemeen,Processor,3 Ghz

I want with one query to select the follow id's: 1,2,3,4,7,8

Because the cat = algemeen and the name = processor by these products. ID 5,6 are only present by product 3.

So, the entry's (cat and name) which are present by all products (product_id) have to be selected.

The database contains 80.000 entry's with a lot of diffrent cat's, name's and value's.

Is this possible with one query or is some php necessary? How do I do this?

My apologies for the bad English.

© Stack Overflow or respective owner

Related posts about php

Related posts about sql