Re: does this require a stored procedure?

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: Alex Rice <alrice(at)ARCplanning(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: does this require a stored procedure?
Date: 2003-05-09 16:47:22
Message-ID: p7mnbv4tn42is323v8ja9jd3orbrrcfcdr@4ax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 8 May 2003 12:50:02 -0600, Alex Rice <alrice(at)ARCplanning(dot)com>
wrote:
>Is it possible to rewrite this SQL query so it returns one row having
>the columns title and contentType, instead of two rows with the sname
>column? [...]
>
># SELECT rec_id, url, sname, sval FROM url, urlinfo
>WHERE url.rec_id = 1821
>AND url.rec_id = urlinfo.url_id
>AND sname in('title','Content-Type');

SELECT u.rec_id, u.url, t.sval AS title, c.sval AS "contentType"
FROM url u
INNER JOIN urlinfo t
ON (u.rec_id = t.url_id AND t.sname = 'title')
INNER JOIN urlinfo c
ON (u.rec_id = c.url_id AND c.sname = 'Content-Type')
WHERE url.rec_id = 1821;

Use LEFT JOINs if it's not sure that there is always a 'title' and a
'Content-Type'.

Servus
Manfred

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Larry Rosenman 2003-05-09 17:59:11 Re: index fragmentation
Previous Message Larry Rosenman 2003-05-09 16:10:55 %ROWTYPE and insert