Re: help in writing query

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "maria s" <psmg01(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, "Ivan Sergio Borgonovo" <mail(at)webthatworks(dot)it>
Subject: Re: help in writing query
Date: 2008-06-10 15:03:25
Message-ID: 162867790806100803i2fb3126fr7a388005073f8687@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

SELECT i.name, p.property_name, p.property_value
FROM sample_info i
JOIN
sample_properties p
ON i.id = p.id

maybe
Pavel

2008/6/10 maria s <psmg01(at)gmail(dot)com>:
> Hello friends,
> I need help in write a query.
>
> I have 2 tables, one is sample_info and sample_properties,
>
> sample_info (id integer, string name)
> ------------------
> 1, c_01
> 2, c_02
> ...
>
> sample_properties(sample_id integer(ref. sample_info), property_name string
> ,property_value string )
> -------------------------
> 1, prop1, value1
> 1, prop2, value2
> 2, prop1, value1
> 2, prop2, value 2
> 2, prop3, value3
>
>
> I would like to get the result by joining 2 tables, for sample id 1 from
> sample_info, the result should be
>
> 1,c_01,value1,value2
>
> for sample 2
>
> 2, c_02,value1,value2,value3
>
> with property_value column header as property_name
>
> Can anyone help me to write a query /function/view to get the above output?
>
> Thank you so much for your help.
>
> -maria
>

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Marlowe 2008-06-10 15:04:57 Re: Nextval & Currval
Previous Message Chris Browne 2008-06-10 14:57:11 Re: One Text Table or Multiple Text Tables - Design Tradeoffs?