Mysql
 sql >> Base de données >  >> RDS >> Mysql

Base de données d'attributs MySQL

Veuillez ne pas utiliser la syntaxe de jointure implicite. Un deuxième ensemble de jointures est nécessaire pour obtenir un deuxième attribut.

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'