dbTalk Databases Forums  

Looking for correct SQL

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Looking for correct SQL in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Alexander Pucher
 
Posts: n/a

Default Looking for correct SQL - 10-14-2004 , 02:46 PM






Hi,

I'm struggling for some time with the following problem:

I have a table like this:

name key value
-------------------------
andi age 23
andi hometown boston
tom age 45
greg hometown miami


I would like to get the following through a SQL Select Statement:


name age hometown
-------------------------
andy 23 boston
tom 45 NULL
greg NULL miami

I thought about a subselect, but could'nt find the clue.

Thanks for any input,
best regards,
alex.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #2  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: Looking for correct SQL - 10-14-2004 , 03:02 PM






On Thu, Oct 14, 2004 at 09:46:33PM +0200, Alexander Pucher wrote:
Quote:
I have a table like this:

name key value
-------------------------
andi age 23
andi hometown boston
tom age 45
greg hometown miami


I would like to get the following through a SQL Select Statement:


name age hometown
-------------------------
andy 23 boston
tom 45 NULL
greg NULL miami
Take a look at the crosstab functions in contrib/tablefunc.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.