WHERE IN语句

时间:2017-07-03 11:42:43

标签: mysql sql where-in

我有以下sql查询:

SELECT `main_table`.* FROM `prd_brand` AS `main_table`
INNER JOIN 
    (SELECT DISTINCT value from catalog_product_entity_int where row_id in 
        (select row_id from catalog_product_entity_int where attribute_id = 97 and value = 1) , 
        (select row_id from catalog_product_entity_int where attribute_id = 99 and value = 4)) t 
ON main_table.brand_id = t.value

是否可以在select语句中添加多个WHERE IN个查询。

顺便说一句,执行查询时我有#1248 - Every derived table must have its own alias

1 个答案:

答案 0 :(得分:3)

我不太确定您的查询尝试了什么。但这似乎是编写逻辑的一种更简单的方法:

SELECT b.* 
FROM `prd_brand` AS b INNER JOIN 
    (SELECT DISTINCT value 
     FROM catalog_product_entity_int 
     WHERE (attribute_id, value) IN ( (97, 1), (99, 4) )
    ) t
    ON b.brand_id = t.value