基于concat列表的mysql命令

时间:2013-10-17 12:50:48

标签: php mysql

我有两张桌子:

  • 产品
  • 属性

products.product_attributes包含与此产品相关的所有属性标识符的concat列表。但我的问题在于排序,concat列表包含手动指定顺序中的所有标识符,但这对结果的顺序没有影响。

如何使用concat列表识别订单?

查询示例:

SELECT * FROM attributes WHERE attribute_id IN(products.product_attributes)

1 个答案:

答案 0 :(得分:2)

感谢@Raymond Nijland,不那么狡猾的解决方案:

   SELECT DISTINCT attributes.* FROM attributes, products 
    WHERE EXISTS(SELECT 1 FROM products WHERE 
    FIND_IN_SET(attribute_id, product_attributes) IS NOT NULL);