Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 7AF751648186 for ; Fri, 30 Mar 2012 22:20:07 -0300 (ADT) Received: from nm2.bullet.mail.ac4.yahoo.com ([98.139.52.199]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SDmz7-0003bj-RA for pgsql-sql@postgresql.org; Sat, 31 Mar 2012 01:20:06 +0000 Received: from [98.139.52.195] by nm2.bullet.mail.ac4.yahoo.com with NNFMP; 31 Mar 2012 01:19:52 -0000 Received: from [98.139.52.161] by tm8.bullet.mail.ac4.yahoo.com with NNFMP; 31 Mar 2012 01:19:52 -0000 Received: from [127.0.0.1] by omp1044.mail.ac4.yahoo.com with NNFMP; 31 Mar 2012 01:19:52 -0000 X-Yahoo-Newman-Id: 733463.8070.bm@omp1044.mail.ac4.yahoo.com Received: (qmail 65004 invoked from network); 31 Mar 2012 01:19:52 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=bLvKReqw47ur+Fcx05H7W6QhG5af/HWX2QPdsHZDXC5h1UsdCSuSgi6CqSIdjeCHtx12T8CrO8McmP/HwrmrUcd9DzjICSq1nRBPipex3joP1WHHcItVFnFsWqxynb7Xp4pv/IBAnx1tCD5NP+tFKkvclftcoYIurCHRlQEvkW4= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333156792; bh=h3rmKeJNS4p9/2JYO6quSQmJJt2rk1pj2n093MjN/l8=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=b5J7tQsziUbbdAOB5YmRAH6QJ5u1K+3x8VZ48UzxwCtQXaAUlomRpwJgcvMzw0AQPLb0EeOHePvOqONcmn4XIa68HKKlDxmRylV8Q5/KdnRg6X2bNQb/taDiWERDKG2Cu4xn0QMWby1H1ZoInqaoJoeCKuNU0M+dccQ22ga43zI= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: COwaK4YVM1l29zB7aMC1Ee6s36WMlP0n6ZLqRUDokBElGuL gq4UhjQgKBJcPT5Hll_q7wuHlvfKNyxzpVyxKdlcvub0UhMsAFhL5_ChGPBP kpEr08XYmN5Zp7MmVRjlpTc8hDsGNwkn_ARGueGPbCOuK8Xvr8eoCaB76TF3 SLOWTtDOH_ZuwO1PbIc7qWXQeHHbeUNTohmnq0gZjdVwV8AEY.cfAIPz_H2. k1JVoS56Fni2kRc7D2MMWOaGJZd4YJ6XlHMNLnO5rzYobCsu3Vcb8PIQu2fh 8S.3FElWYDCPYCc3tD5eTaoyo3sn9MVZ9STyvBc7l3zZ9vnxUiw1Phcwgj32 BJRCh7ZVxVznB0JWSMJnfNowhPxobfYWTJO5cZ_Psn063mS_XwCTJYzlYDUW JVlJKjvFKpMryItBIRUDq4drqYe7_ntQw_CqSPVAV8m135aEZmfpTbhCytoD OSel4Zv1k1X_FMnjuYlH76XMPxu54m0A- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [192.168.33.107] (polobo@98.177.224.209 with xymcookie) by smtp106-mob.biz.mail.ac4.yahoo.com with SMTP; 30 Mar 2012 18:19:52 -0700 PDT References: <201203281501.38835.gary.stainburn@ringways.co.uk> In-Reply-To: <201203281501.38835.gary.stainburn@ringways.co.uk> Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: <2F810199-0078-400F-AF95-F04F6BFAB4B0@yahoo.com> Cc: "pgsql-sql@postgresql.org" X-Mailer: iPad Mail (9B176) From: David Johnston Subject: Re: Wrong output from union Date: Fri, 30 Mar 2012 18:19:50 -0700 To: Gary Stainburn X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/82 X-Sequence-Number: 36477 Documented behavior. Please read the section on UNION for the why and the p= roper alternative syntax: http://www.postgresql.org/docs/9.0/interactive/sql-select.html On Mar 28, 2012, at 7:01, Gary Stainburn wro= te: > Hi folks. >=20 > I have two selects which in themselves report what they should. However, w= hen=20 > I run a union to combine their outputs (to then feed a select/count) lines= =20 > disappear. Below are the two seperate selects, followed by the untion in=20= > which duplicate rows are lost. I'm using Postgresql 8.3.3-2 RPMs on a Fedo= ra=20 > 9 system. >=20 > Can anyone tell me why it is happening and how to fix it. >=20 > Ta. >=20 > users=3D# select r_u_id || ':' ||r_deadline as key from requests where r_u= _id is=20 > not NULL and r_deadline>=3D'2012-03-26' and r_deadline <=3D ('2012-03-26':= :date=20 > + '7 days'::interval); = =20 > key > --------------- > 25:2012-03-28 > 25:2012-03-28 > 25:2012-03-28 > 25:2012-03-30 > 25:2012-03-29 > 25:2012-03-27 > (6 rows) >=20 > users=3D# select u_id || ':' || rm_timestamp::date as key from request_rem= inders=20 > where u_id is not null and rm_timestamp>=3D'2012-03-26' and rm_timestamp <= =3D=20 > ('2012-03-26'::date + '7 days'::interval); > key > ----- > (0 rows) >=20 > users=3D# select r_u_id || ':' ||r_deadline as key from requests where r_u= _id is=20 > not NULL and r_deadline>=3D'2012-03-26' and r_deadline <=3D ('2012-03-26':= :date=20 > + '7 days'::interval) = =20 > union = =20 > select u_id || ':' || rm_timestamp::date as key from request_reminders whe= re=20 > u_id is not null and rm_timestamp>=3D'2012-03-26' and rm_timestamp <=3D=20= > ('2012-03-26'::date + '7 days'::interval); > key > --------------- > 25:2012-03-27 > 25:2012-03-28 > 25:2012-03-29 > 25:2012-03-30 > (4 rows) >=20 > users=3D# > --=20 > Gary Stainburn > Group I.T. Manager > Ringways Garages > http://www.ringways.co.uk=20 >=20 > --=20 > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql