Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL-Attributdatenbank

Bitte verwenden Sie keine implizite Join-Syntax. Ein zweiter Satz von Joins ist erforderlich, um ein zweites Attribut zu erhalten.

SELECT upa1.value, upa2.value, up1.status, u1.status 
  FROM product p
    /* These joins get attribute/value for 'username' attribute */
    INNER JOIN product_attribute pa1
      ON p.product_id = pa1.product_id
        AND pa1.attribute_name = 'username'
    INNER JOIN user_product_attribute upa1
      ON pa1.product_attribute_id = upa1.product_attribute_id
    INNER JOIN user_product up1
      ON upa1.user_product_id = up1.user_product_id
    INNER JOIN user u1
      ON up1.user_id = u1.user_id 
    /* These joins get attribute/value for 'domain' attribute */  
    INNER JOIN user_product_attribute upa2 
      ON upa1.user_product_id = upa2.user_product_id
    INNER JOIN product_attribute pa2
      ON upa2.product_attribute_id = pa2.product_attribute_id            
        AND pa2.attribute_name = 'domain'
  WHERE p.product_name = 'email'