Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Expand UserMeta table to flat view (rows to columns)
S
✭✭
Example UserMeta table.
+--------+----------------+-------------------+I wondered whether it is possible to make this as flat view by mysql view (or procedure, function, or trigger) for easy building queries. I want to see this zoo above as:
| UserID | Name | Value |
+--------+----------------+-------------------+
| 3 | FirstName | FIRSTNAME276 |
| 5 | FamilyName | FAMILYNAME885 |
| 3 | PatronymicName | PATRONYMICNAME461 |
| 2 | FirstName | FIRSTNAME387 |
| 4 | FamilyName | FAMILYNAME818 |
| 2 | PatronymicName | PATRONYMICNAME710 |
| 5 | PatronymicName | PATRONYMICNAME109 |
+--------+----------------+-------------------+
+--------+-----------+-----------+-----------+-----------+Any advice?
| UserID | MetaName1 | MetaName2 | MetaName3 | .... | MetaNameN |
+--------+-----------+-----------+-----------+-----------+
....
+--------+-----------+-----------+-----------+-----------+
0
Comments
EAV... this is the first I've heard about it. Interesting for me.
Anyway, Google suggested below link to me.
http://www.artfulsoftware.com/infotree/queries.php#78
As you may already know, but just to let you know.
YES! This link has helped me very much. Many thanks.
Didnt reliaze about it (googgle gives me nothing usefull on "eav + transpose", etc).
And yes UserMeta table it is EAV model structure, but not fully normalized.
You can read more about EAV at wikipedia.org Entity-attribute-value model
I already write "rows to columns" procedure for UserMeta
Here it is: And there are some problems:
1) We must call this every time when new Attribute 'Name' appeared in table.
2) Building part of query looks scary, construction select group_concat(Name separator ',') from (select distinct Name from GDN_UserMeta) + string functions.
3) Table Prefix fixed in procedure body.