Received: from Poopsie.hmsc.orst.edu (edstrom@poopsie.HMSC.ORST.EDU [128.193.170.162]) by hub.org (8.8.8/8.7.5) with ESMTP id OAA21073 for ; Mon, 3 Aug 1998 14:54:34 -0400 (EDT) Received: (from edstrom@localhost) by Poopsie.hmsc.orst.edu (8.8.7/8.8.7) id LAA03398 for pgsql-sql@postgreSQL.org; Mon, 3 Aug 1998 11:54:31 -0700 Date: Mon, 3 Aug 1998 11:54:31 -0700 From: John Edstrom Message-Id: <199808031854.LAA03398@Poopsie.hmsc.orst.edu> To: pgsql-sql@postgreSQL.org Subject: Re: [SQL] locked my keys in the car > > And so I tried this here: > > SELECT tr_id, tr_date FROM crtrd1 > WHERE tr_unit = 'SMA' AND (tr_type = 'A' OR tr_type = 'I') > AND tr_date > tr_date IN > (SELECT tr_date FROM crtrd1 > WHERE tr_unit = 'SMA' AND (tr_type = 'T' OR tr_type = 'O')) > ORDER BY tr_date DESC; > How about CREATE FUNCTION F(int,char) returns int4 as 'SELECT max(tr_date) FROM crtd1 WHERE $1=tr_id AND $2=tr_unit AND (tr_type = \'A\' OR tr_type = \'I\');' language 'sql'; and then search as: SELECT distinct tr_id,F(tr_id) from crtd1;