Originally created and last_mod by whom and when ?

From: Aarni Ruuhimäki <aarni(at)kymi(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Originally created and last_mod by whom and when ?
Date: 2007-11-14 11:06:34
Message-ID: 200711141306.34996.aarni@kymi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

In a web app (Pg 8.2.4 + php) I have product and other tables with fields like

product_created timestamp without time zone
product_created_user_id integer
product_last_mod timestamp without time zone
product_last_mod_user_id integer

The person who last modified an item can obviously be someone else who
originally created it.

I can get the names and timestamps with two separate queries but how can I do
a single query to get the names of both ?

product_id | 1
...
product_created_user_id | 1
product_last_mod_user_id | 2

ID 1, created by X / date and time, last_mod by Y / date and time

And a similar query to only one table, users ?

user_id integer
user_forename text
...
user_created timestamp without time zone
user_created_user_id integer
user_last_mod timestamp without time zone
user_last_mod_user_id integer

ID 4, name Z, created by X / date and time, last_mod by Y / date and time

Join, sub select ? I tried some but only managed to get only one name, errors,
nothing at all or two rows with inner join + union ...

Lotsa thanks for any help,

Aarni
--

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2007-11-14 11:28:55 Re: Originally created and last_mod by whom and when ?
Previous Message Erik Jones 2007-11-13 15:33:23 Re: design of tables for sparse data