This might be basic, but I’m at a loss here …
I have two tables, one with articles and one with their attributes.
I need to select multiple attributes for specific articles.
Articles-table:
Article | Description | Category |
---|---|---|
A00001 | First item | X |
A00002 | Second item | X |
A00003 | Third item | Z |
Attributes-table:
Article | Attribute | Value |
---|---|---|
A00001 | Height | 1000 |
A00001 | Width | 2000 |
A00001 | Depth | 3000 |
A00002 | Height | 4000 |
A00002 | Width | 5000 |
A00002 | Depth | 6000 |
Desired result:
Article | Description | Category | Height | Width |
---|---|---|---|---|
A00001 | First item | X | 1000 | 2000 |
A00002 | Second item | X | 4000 | 5000 |
Mid-posting-update:
Whilst writing this, I found a solution myself – I’ll post it anyway, in case anyone ever stumbling upon the same task (or has a better solution to offer):
SELECT
Articles.Article,
Articles.Description,
Articles.Category,
Att1.Values as Heigh,
Att2.Values as Width
FROM Articles
JOIN Attributes AS Att1 ON Articles.Article = Att1.Article AND Att1.Attribute = 'Height'
JOIN Attributes AS Att2 ON Articles.Article = Att2.Article AND Att2.Attribute = 'Width'
WHERE Articles.Category = 'X'
New contributor
user24663749 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.