I need to extract results from one table organized as EAV-feed repository. What I need is return results like a relational table. I'm using an schema like that:
Table Schema
meta table
-----------------------
idmeta | entity_identity(fk) | products_idproduct(fk) | products_feeds_idfeed(fk) | value |
1 | 1 | 1 | 1 | First product first val |
2 | 2 | 1 | 1 | First product second val|
3 | 1 | 2 | 1 | 2nd product first val |
4 | 2 | 2 | 1 | 2nd product second val |
5 | 1 | 3 | 1 | 3rd product first val |
6 | 2 | 3 | 1 | 3rd product second val |
So I'm trying to extract all values from all products for each idfeed. In this case I'm trying to get somethig like this:
Wanted results..
+----------------------+---------------------------+---------------------------+
| products_idproduct | field1 | field2 |
+--------------------+--------------------------+------------------------------+
| 1 | First product first val | First product second val |
+--------------------+--------------------------+------------------------------+
| 2 | 2nd product first val | 2nd product second val |
+--------------------+--------------------------+------------------------------+
| 3 | 3rd product first val | 3rd product second val |
+--------------------+--------------------------+------------------------------+
I've been trying with some coalescing sentences but all I'm getting only one row because the MAX function, or some NULL values instead..:
What I'm trying now..
SELECT DISTINCT products_idproduct
, MAX( IF(entity_identity = 1, value, NULL) ) as 'field1'
, MAX( IF(entity_identity = 2, value, NULL) ) as 'field2'
FROM meta
WHERE products_feeds_idfeed = 1;
And obsiously this only returns the last line (last product)..
+----------------------+---------------------------+---------------------------+
| products_idproduct | field1 | field2 |
+--------------------+--------------------------+------------------------------+
| 3 | 3rd product first val | 3rd product second val |
+--------------------+--------------------------+------------------------------+
Any ideas about how can I get all product results like a relational table?