Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLxkI-0002Pp-SD for pgsql-sql@arkaria.postgresql.org; Tue, 17 Sep 2013 16:03:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VLxkI-0000G6-Bk for pgsql-sql@arkaria.postgresql.org; Tue, 17 Sep 2013 16:03:22 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLxkH-0000Ej-2r for pgsql-sql@postgresql.org; Tue, 17 Sep 2013 16:03:21 +0000 Received: from mail-qc0-x22c.google.com ([2607:f8b0:400d:c01::22c]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VLxkD-0003gw-Um for pgsql-sql@postgresql.org; Tue, 17 Sep 2013 16:03:20 +0000 Received: by mail-qc0-f172.google.com with SMTP id l13so3768690qcy.3 for ; Tue, 17 Sep 2013 09:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=bKdMGEorG/kiPHNG1Mh/tEqCaMThw07SqUwwLBUa5dU=; b=kGwrMRYj4Uf66PII3E8Dhuq0d+etDtslssO2KpPiAO8UnjP9Q+3hFv/tIduG5bgbt5 7EgBSynnOD6kJPTaQHVjH56XEOa5ArWXo8bThXS8+AgTCB3DJmMwe9brQPQ5GJkm/77v AUoo+3TzI3pJgCfR/bBDvv9k08s0OVAeQ0CAnMdKKVgFX6NtF9AMbxRi+N5cCbzEBQrP gmjcsDXhhy5VlGjro8RqEVXQYWHAckbJb8+JJ11UOliR7K56eGyo/rMF82ZpAFWbNkve nxj+OK7wPxuevfbpGdhMrdhqq3+4FA1Eyf/LXy+HGqkjk1mKTY+bgWvJ4RgzeY30tqqZ RhbQ== X-Received: by 10.49.75.103 with SMTP id b7mr4342515qew.85.1379433796604; Tue, 17 Sep 2013 09:03:16 -0700 (PDT) Received: from [192.168.219.51] (cpe-098-026-158-044.triad.res.rr.com. [98.26.158.44]) by mx.google.com with ESMTPSA id h2sm56585624qev.0.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Sep 2013 09:03:16 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: removing duplicates and using sort From: Nathan Mailg In-Reply-To: <1379342569452-5771096.post@n5.nabble.com> Date: Tue, 17 Sep 2013 12:03:15 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <309ABE98-2643-4E6B-B5C9-FF68271B9661@gmail.com> References: <1379342569452-5771096.post@n5.nabble.com> To: pgsql-sql@postgresql.org X-Mailer: Apple Mail (2.1508) X-Pg-Spam-Score: 0.7 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Yes, that's correct, modifying the original ORDER BY gives: ORDER BY lastname, firstname, refid, appldate DESC; ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressi= ons Using WITH works great: WITH distinct_query AS ( SELECT DISTINCT ON (refid) id, refid, lastname, firstname, appldate FROM appl WHERE lastname ILIKE 'Williamson%' AND firstname ILIKE 'd= %' GROUP BY refid, id, lastname, firstname, appldate ORDER BY refid, appldate DESC ) SELECT * FROM distinct_query ORDER BY lastname, firstname; Thank you! --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql