I have a table for settings, which can be shown as: object_id (int) key (varchar) value (text)
I am trying to grab the object_id that has key's equal to 2 items.
SELECT `object_id` FROM `settings` WHERE `key` = 'A' AND `key` = 'B'
I know that won't work, the only way I can think of doing this is joining it on itself:
SELECT a.`object_id` FROM `settings` AS a LEFT JOIN `settings` AS b ON ( a.`object_id` = b.`object_id` ) WHERE a.`key` = 'A' and b.`key` = 'B'
While I haven't tested the last statement, I'm sure something like this could work. This query will be performed on potentially hundreds of thousands of records every hour, so I want to keep it optimized -- is there a better way to do this?