I am building a dynamic application. I have three tables : ( EAV model style)
- Items ( ItemId, ItemName)
- Fields (FieldId, FieldName)
- Field Values ( ItemID, FieldId, Value)
Can you tell me how to write SINGLE query to get starting 20 records from ALL items where FieldId=4 is equal to TRUE.
Expected Result :
Columns => ItemID | Name | Field1 | Field2 | Field3
Each Row=> ItemId | ItemName| Value1 | Value2 | Value3
Important concerns :
- Number of fields per item are not known
- I need one to write ONE query.
- Query will be running on 100K records, so performance is concern.
- I am using MySQL 5.0, so need solution for MYSQL
Should I denormalize the tables if above query is not possible at all ? Any advice ?