Can you solve this simple SQL query?

后端 未结 3 852
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 20:31

Suppose it\'s a website that sells photo cameras. Here are my entities (tables):

Camera: A simple camera
Feature: A feature like: 6mp, max resolution 1024x76         


        
3条回答
  •  自闭症患者
    2021-01-14 20:51

    SELECT DISTINCT Camera.*
    FROM Camera c
         INNER JOIN cameras_features fc1 ON c.id = fc1.camera_id AND fc1.feature_id = 1
         INNER JOIN cameras_features fc2 ON c.id = fc2.camera_id AND fc2.feature_id = 2
    

    What is happening here is that cameras will be filtered down to cameras with feature 1, then within this group, the cameras are gonna be filtered down to the ones with feature 2

提交回复
热议问题