logo       

Re: Turning column into row: msg#00243

Subject: Re: Turning column into row
> -----Original Message-----
> From: pgsql-sql-owner@xxxxxxxxxxxxxx
> [mailto:pgsql-sql-owner@xxxxxxxxxxxxxx]On Behalf Of Wm. G. Urquhart
> Sent: Wednesday, May 22, 2002 8:41 AM
> To: Tille, Andreas
> Cc: PostgreSQL SQL
> Subject: Re: [SQL] Turning column into row
>
>
> On Wed, 22 May 2002, Tille, Andreas wrote:
>
> > I have a Table of certain items
> >
> >    create table item (
> >        IdItem      int,
> >        Item        varchar(64),
> >        ...
> >    );
> >
> > a lookuptable which defines some properties
> >
> >    create table property (
> >        IdProperty  int,
> >        Property    varchar(64)
> >    );
> >
> > and a table which defines the different properties which are
> possible for
> > a certain item:
> >
> >    create table tlkp_item_property (
> >        IdItem     int,
> >        IdProperty int
> >    );
> >
> > So I can easily select all the properties of a certain item in a table
> > where the columns contain the properties.  But I want to have an output
> > of the kind
> >
> >     Item 1: Property 1, Property 2, Property 3, ...
> >     Item 2: <Properties of Item 2>
> >        ...
> >
> > So I have to turn the different properties according to one item into
> > one field insead of one column.

If you can have the properties listed in one field, rather than in separate
fields, you can use a list aggregator, such as the one at:
http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=13
9

SELECT Item.iditem, comma(property) FROM Item JOIN Tlkpitem_Property USING
(iditem) JOIN Property USING (idproperty);

If this won't work, let us know. There are SELECT statements that will
create the output in separate fields, they're just either slow or require
minor modifications to your tables.

- J.

Joel BURTON | joel@xxxxxxxxxxxxxx | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe