Re: does this require a stored procedure? - Mailing list pgsql-sql

From Manfred Koizar
Subject Re: does this require a stored procedure?
Date
Msg-id p7mnbv4tn42is323v8ja9jd3orbrrcfcdr@4ax.com
Whole thread Raw
In response to does this require a stored procedure?  (Alex Rice <alrice@ARCplanning.com>)
List pgsql-sql
On Thu, 8 May 2003 12:50:02 -0600, Alex Rice <alrice@ARCplanning.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')WHEREurl.rec_id = 1821;
 

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

ServusManfred



pgsql-sql by date:

Previous
From: Larry Rosenman
Date:
Subject: %ROWTYPE and insert
Next
From: Wei Weng
Date:
Subject: index fragmentation