From: | Yury Don <yura(at)vpcit(dot)ru> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: weird structure |
Date: | 2000-08-25 03:27:32 |
Message-ID: | 39A5E7A4.E928FC2C@vpcit.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
rdg(at)viafractal(dot)com(dot)br wrote:
>
> Hi,
>
> Consider the following tables/fields:
> table "person": fields "p_id", "p_name".
> table "person_attribute": fields "a_id", "a_name".
> table "person_data": fields "d_person_id", "d_attribute_id",
> "d_value".
>
> Also consider that a person may not have data related to all possible
> attributes.
>
> Using this structure, how could I retrieve in one row with a single
> select statement all attributes from a person (showing null to
> attributes that were not registered to him)?
>
> Thanks for any suggestion,
> --
> Renato
> Sao Paulo - SP - Brasil
> rdg(at)viafractal(dot)com(dot)br
I did similar things using the following technique:
in frontend I gather all attributes from person_attribute and then
generate a query like this:
select *, (select distinct d_value from person_data where d_person_id =
person.p_id and
d_attribute_id = 'here first attribute id'), (select distinct d_value
from person_data where d_person_id = person.p_id and d_attribute_id =
'here second attribute id'), ... from person
--
Sincerely yours,
Yury
From | Date | Subject | |
---|---|---|---|
Next Message | Yury Don | 2000-08-25 03:31:03 | Re: [GENERAL] Getting the result of a query using COUNT(*) |
Previous Message | Rodger Donaldson | 2000-08-25 03:13:34 | Regular expression query |