Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Select last there dates



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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group