I‘m not even going to pretend understanding that design.
Yes, this design is ugly. I've not implemented yet. Just thinking over. Problem is the "property" names may change, so that I cannot fix fields at design time.
It is IMHO a pivot tranformation
I know this for firebird and it says it is not dynamic possible
You are right. This is pivot transformation. I know that MS-dbs support this functionality. But I do not need dynamic capability. I can make the SQL statement at Lazarus and query it.
@paweld:
Your suggestion is interesting. But not does not operate correctly for this case, I'm afraid. It produces three rows if all additional three columns are not null.
I have came up with another SQL statement. Cannot decide on which one is better between below and previous one using JOIN. First principle: the simpler, the better! But which one is simpler? ^^
SELECT s.*,
(SELECT key_value FROM sample_data WHERE pid=s.pid AND rid=s.rid AND key_name='Gender') Gender,
(SELECT key_value FROM sample_data WHERE pid=s.pid AND rid=s.rid AND key_name='Age') Age,
(SELECT key_value FROM sample_data WHERE pid=s.pid AND rid=s.rid AND key_name='Occp') Occp
FROM samples s