[thelist] Postgres / General SQL question...

Tris beertastic at gmail.com
Wed Feb 4 07:13:28 CST 2009

Hi all...
I'm trying to retrieve a result set using only one sql statement.

I've a 2 tables I'm joining to: users, locations

a user can exist in multiple (though we limit it to 5) locations, and
I've been asked to produce a report that has 6 columns
User Id
Location 1
Location 2
Location 5

I can export all users with each location on it's own row.. but I
don't know how to tell postgres to treat each instance of a location
and apply it to the next column, rather than the next row.
I'm limited to using a complicated admin system that I can can't
really edit too much, hence my being limited to one query.
I suspect that being that the query just loops until all results are
found, that I can't do what i'm after... due to the fact that once
Location 1 has been flagged, it starts a new row..

I'm heartily confused and on goolgle now looking for ideas...
do you guys have any?


"The only people who don't make mistakes are those who don't do anything"

Give a man a fish and he'll feed himself for a day.
Give a man a religion and he'll starve to death praying for a fish.

`We are what we pretend to be, so we must be careful what we pretend to be.`
Kurt Vonnegut

`When a person can no longer laugh at himself, it is time for others
to laugh at him.`
Thomas Szasz

More information about the thelist mailing list