如果特定 location_id 的以下两个条件都为真,则想要从 location_context 表中获取 location_id
SELECT location_id
FROM location_context
WHERE relation_type = '2'
AND relation_table = 'locations'
AND relation_table_id = '$_GET[cat]'
AND is_active = '1'
和
SELECT location_id
FROM location_context
WHERE relation_type = '1'
AND relation_table = 'locations'
AND relation_table_id = '$_GET[pro]'
AND is_active = '1'
最佳答案
这是您要查找的查询:
SELECT L.location_id
FROM location_context L
WHERE L.relation_table = 'locations'
AND L.is_active = '1'
AND ((L.relation_type = '2' AND L.relation_table_id = '$_GET[cat]')
OR (L.relation_type = '1' AND L.relation_table_id = '$_GET[pro]'))
希望对你有帮助
关于php - 想要合并两个 sql 查询以获得共同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26101945/