简体   繁体   English

用于匹配一列中的多个值的SQL查询

[英]Sql query for matching multiple values in one column

dfsdfi have these tables dfsdfi有这些表

product 产品

product_id      name
51                a
52                 b
53                 c
54                 s
55                 e

product_filter product_filter

product_id      filter_id
52                 11
53                 22
54                 33
52                 22
54                 11

filter_group_description filter_group_description

filter_group_id     filter_id        name
1                     11             white  
1                     22             black
2                     33             formals
2                     44             casuals

filter_group filter_group

filter_group_id      name
1                   Colour
2                   Style  

What i want here is product name where colour is black and white but style should be formals.. 我想要的是产品名称,颜色是黑色和白色,但风格应该是正式的..

I think you need something like this: 我想你需要这样的东西:

SELECT * FROM product_filter p 
INNER JOIN filter_group f ON f.filter_id = p.filter_id 
WHERE p.filter_id IN (11,22,33,44)

If you just want to get back some columns, change the * 如果您只想返回一些列,请更改*

SELECT p.product_id, p.filter_id, f.filter_group_id
FROM `product_filter` p
JOIN `filter_group` f
ON p.filter_id = f.filter_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM