From: David Gardner <david@gardnerit.net>
To: Loredana Curugiu <loredana.curugiu@gmail.com>
To: pgsql-novice@postgresql.org
Subject: Re: Select last there dates
Date: Thu, 21 Jun 2007 06:47:53 -0700
Message-ID: <467A8189.2050309@gardnerit.net> (raw)
In-Reply-To: <1c23c8e70706210118h6b9490e3s11e2a6ba15cdff6c@mail.gmail.com>
References: <1c23c8e70706210118h6b9490e3s11e2a6ba15cdff6c@mail.gmail.com>
I'm not sure about getting all the dates into a single comma separated
field, if table two had a unique id field, say table2.id then this
should retrieve the last three dates per phone number:
SELECT table1.uid, table1.phone_number, table2.id, table2.date
FROM table1 JOIN table2 ON table1.uid=table2.uid
AND table1.phone_number=table2.phone_number
WHERE table1.uid = 8
AND (table2.id IN
(SELECT id FROM table2
WHERE table2.phone_number = table1.phone_number
ORDER BY table2.date DESC LIMIT 3 ));
--
David Gardner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: david@gardnerit.net, loredana.curugiu@gmail.com, pgsql-novice@postgresql.org
Subject: Re: Select last there dates
In-Reply-To: <467A8189.2050309@gardnerit.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox