Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAAq0-0005zZ-OU for pgsql-sql@arkaria.postgresql.org; Wed, 19 Jan 2022 13:17:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAApz-0003r3-JT for pgsql-sql@arkaria.postgresql.org; Wed, 19 Jan 2022 13:17:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAApz-0003qn-Ah for pgsql-sql@lists.postgresql.org; Wed, 19 Jan 2022 13:17:19 +0000 Received: from mail.klingler.net ([2a02:c207:2032:8354::1]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAApu-00019h-Hs for pgsql-sql@lists.postgresql.org; Wed, 19 Jan 2022 13:17:18 +0000 Date: Wed, 19 Jan 2022 14:17:11 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=klingler.net; s=2020; t=1642598232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vBxgpcg9quAuPcPpHeUrkgyC/MbQRn4nNw2o9LAYAes=; b=SFiGD07CsYXyKIF/bJMbV7XVeSjquomBwMvWNxaZhRqAUC/6sRG2biayX8GWQhEZByXgVS LzDoSVoB4sda+pPuHr93zocPn6k+7BZPxZRM9R30TKupgB8lQC//12KI2tKFUPkF7DWNlO 11tAZvQ+NHV5Q6lgktKm6Zjbu9imfco= From: Richard Klingler To: Rob Sargent Cc: pgsql-sql@lists.postgresql.org Message-ID: <20220119141711201637.c796844d@klingler.net> In-Reply-To: <72f379a3-0bba-b0fb-975c-d20b76d33fff@gmail.com> References: <20220119120317479683.54287f97@klingler.net> <9713782b-9c29-2497-be30-6dd1af0d550c@gmail.com> <20220119134059286538.4c015b19@klingler.net> <72f379a3-0bba-b0fb-975c-d20b76d33fff@gmail.com> Subject: Re: Clean up shop database MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Authentication-Results: ORIGINATING; auth=pass smtp.auth=richard@klingler.net smtp.mailfrom=richard@klingler.net List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 19 Jan 2022 05:56:17 -0700, Rob Sargent wrote: > On 1/19/22 05:40, Richard Klingler wrote: >> Odd...gives me the same result.... >> >> Tried another approach as the ordered is known where to start >> from....but still the same: >> >> select p.productid as id, p.name_de as name >> from product p, orderitems i,orders >> where p.productid = i.orderitems2productid >> and i.orderitems2orderid = orders.orderid >> and orders.orderid < 14483 >> and p.pieces < 1 >> and p.active = 't' >> group by id >> order by id desc >> >> Still lists products after January 1st 2021...but I know what is going >> on.... > > (On this list top-posting is frowned upon. Inline or bottom-posting > preferred.) > The above query does not restrict order date? > > select p.*,max(o.orderdate) > from product p join orderitem t on p.productid = t.orderitems2productid > join order o on t.orderitems2orderid = o.orderid > group by p.productid > having max(o.orderdate < 'January 1 2021' > Ah sorry for that..... No it does not...but I assume it lists products that where at least ordered before January 1st 2021 as it contains lower product IDs. Hmm..gives me: > ERROR: function max(boolean) does not exist LINE 5: having max(o.orderdate < '2021-01-01')