0

I have a table called "attributes" which i need to be columns in our query. These columns need to then join our "products" table and be populated with the data from "productattributevalues".

Table: Attributes

Fields:

  • id
  • name

Table: Products

Fields

  • id
  • name
  • description
  • other fields which contain more information about the product

Table: ProductAttributeValues

Fields:

  • id
  • attribute id
  • product id
  • value

How can I get the rows from attributes to be columns alongside the products and have them populated with the values from productattribute values and have unique results.

adamias
  • 77
  • 11

1 Answers1

0

If you know how many attributes you have you can join against the attribute table multiple times. If you don't know how many you could use GROUP_CONCAT. Check out this answer for GROUP_CONCAT .

You could also use a second query to get them, which is a practical choice for many use cases.

Community
  • 1
  • 1
Assaf Karmon
  • 915
  • 1
  • 10
  • 23