From: Jeremy Smith <jer@highboard.com>
To: pgsql-sql@postgresql.org
Subject: DISTINCT ON troubles
Date: Thu, 19 Feb 2004 13:10:30 -0500
Message-ID: <FKEOIJEHOIKIOEHCGNCLEENEEDAA.jer@highboard.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0402190936220.6395-100000@css120.ihs.com>
Hi,
I have a query that reads:
SELECT DISTINCT ON (messageboard.threadid) messageboard.threadid,
messageboard.topic, owner.ownerid, owner.username FROM messageboard, owner
WHERE messageboard.ownerid=owner.ownerid AND messageboard.leagueid =
'$leagueid' ORDER BY messageboard.messageid DESC LIMIT $entries_on_page
OFFSET $beginThread"
The purpose of this query is to retrieve unique threadid's in the order of
the most recent posts that have been made to each thread. When I use this
query I get an error that:
"SELECT DISTINCT ON expressions must match initial ORDER BY expressions".
Of course, if I put ORDER BY threadid in the query it would order it in the
order that the thread was created, not in the last post made.
I have tried using GROUP BY threadID, I get a similar order.
Am I just approaching this all wrong and need to create a temporary table
and draw from that, or is there a way to salvage this query?
Thanks so much,
Jeremy
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: jer@highboard.com
Subject: Re: DISTINCT ON troubles
In-Reply-To: <FKEOIJEHOIKIOEHCGNCLEENEEDAA.jer@highboard.com>
* 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