I have the following tables:
Table configs:
id config
1 ip
2 os
3 cpu
Table options
id config_id option
1 1 127.0.0.1
2 1 192.168.0.1
3 2 windows
4 2 linux
5 3 AMD
6 3 Intel
The config_id column in table options is a foreign key to the id field in table configs
I have a third table users_configs that links users with configs and options like so:
Table users_configs
id user_id config_id, option_id
1 123 1 1
2 456 2 2
3 789 3 3
I would like to get all users that have the following both options at the same time:
- os: windows
- cpu: AMD
I tried the following query, but because of the OR, this returns all users that have either os:windows OR cpu: AMD.
SELECT * FROM users_configs
LEFT JOIN options ON options.id = users_configs.option_id
WHERE (options.config_id = 2 OR options.config_id = 3)
Any help will be appreciated thanks.