pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedlist variable attributes in one select
2+ messages / 2 participants
[nested] [flat]
* list variable attributes in one select
@ 2007-01-22 07:43 Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
2007-01-22 08:24 ` Re: list variable attributes in one select A. Kretschmer <andreas.kretschmer@schollglas.com>
0 siblings, 1 reply; 2+ messages in thread
From: Louis-David Mitterrand @ 2007-01-22 07:43 UTC (permalink / raw)
To: pgsql-sql
Hello,
I've got the following tables:
person:
- id_person
- firstname
- lastname
- type
person_to_type:
- id_person references person
- type references person_type;
person_type:
- type
"person_type" contains differents caracteristics for a person (actor,
director, author, etc.) who can have several types, hence the need for
the person_to_type table.
I'd like to know if I can list in one SELECT command a person and all of
its types, given that the number of types can be 0 to n.
For example, for a given person I'd like to obtain:
"John Doe", "actor", "playright", "author"
or
"Jane Doe", "director"
in one select.
Is that possible?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: list variable attributes in one select
2007-01-22 07:43 list variable attributes in one select Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
@ 2007-01-22 08:24 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
0 siblings, 0 replies; 2+ messages in thread
From: A. Kretschmer @ 2007-01-22 08:24 UTC (permalink / raw)
To: pgsql-sql
am Mon, dem 22.01.2007, um 8:43:48 +0100 mailte Louis-David Mitterrand folgendes:
> "person_type" contains differents caracteristics for a person (actor,
> director, author, etc.) who can have several types, hence the need for
> the person_to_type table.
>
> I'd like to know if I can list in one SELECT command a person and all of
> its types, given that the number of types can be 0 to n.
>
> For example, for a given person I'd like to obtain:
>
> "John Doe", "actor", "playright", "author"
>
> or
>
> "Jane Doe", "director"
>
> in one select.
Yes,
imagine, you have 2 tables:
test=*# select * from f1;
id | name
----+------
1 | foo
2 | bar
3 | batz
(3 rows)
test=*# select * from f2;
i_id | f1_id
------+-------
1 | 1
1 | 2
2 | 1
2 | 2
2 | 3
(5 rows)
f1 contains your characteristics, f2 contains the assignment person ->
characteristics.
Now you can see all characteristics for person with id=1:
test=*# select array_to_string(array(select name from f1 where id in (select f1_id from f2 where i_id = 1)), ', ');
array_to_string
-----------------
bar, foo
(1 row)
Hope that helps, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-01-22 08:24 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-01-22 07:43 list variable attributes in one select Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
2007-01-22 08:24 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox