Database EAV model, record listing as per search
Posted
by Shyam Sunder Verma
on Stack Overflow
See other posts from Stack Overflow
or by Shyam Sunder Verma
Published on 2010-05-16T11:20:50Z
Indexed on
2010/05/16
11:30 UTC
Read the original article
Hit count: 306
I am building a dynamic application. I have three tables : ( EAV model style)
1: Items ( ItemId, ItemName)
2: Fields (FieldId, FieldName)
3: 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 :
1: Number of fields per item are not known
2: I need one to write ONE query.
3: Query will be running on 100K records, so performance is concern.
4: 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 ?
© Stack Overflow or respective owner