Suppose this is a site that sells cameras. Here are my entities (tables):
Camera: A simple camera Feature: A feature like: 6mp, max resolution 1024x768,
The fact is, between the cameras and the function, I have a Many to Many relationship, so I have an additional table:
camera -> cameras_features -> feature
So the request is simple:
How to get all cameras with function 1,2 and 3?
This is similar to building a raster image index.
Data you can use to check if this solution is normal
C1 has features 1,2,3 C2 has features 1,2,4 C3 has features 1,2
Here are the queries and the expected result:
- Show all cameras with functions 1,2 and 3: C1
- Show all cameras with functions 1,2 and 4: C2
- Show all cameras with functions 1 and 2: C1 , C2 and C3
Here is what I did (it works, but it is really ugly, does not want to use it):
SELECT * FROM camera c WHERE c.id IN ( (SELECT c.id FROM camera c JOIN cameras_features f ON (c.id=f.camera_id) WHERE f.feature_id=1) q1 JOIN