Received: from mail_exchange.westcountrypublications.co.uk ([195.171.163.135]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f7LAhrP37401 for ; Tue, 21 Aug 2001 06:43:53 -0400 (EDT) (envelope-from SHenshall@westcountrypublications.co.uk) Received: by MAIL_EXCHANGE with Internet Mail Service (5.5.2650.21) id ; Tue, 21 Aug 2001 11:43:07 +0100 Message-ID: From: "Henshall, Stuart - WCP" To: "'Mark Mikulec'" , pgsql-sql@postgresql.org Subject: RE: Sequential select queries...?? Date: Tue, 21 Aug 2001 11:43:05 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain X-Archive-Number: 200108/265 X-Sequence-Number: 4512 If you want to know for each individual one wether both equal or not you could do: SELECT *,NOT ((name=description) IS NULL) AND (name=description) AS both FROM t WHERE name='bleh' OR description='bleh'; If you wanted totals of the same you could do: SELECT count(*) AS tot,NOT ((name=description) IS NULL) AND (name=description) AS both FROM t WHERE name='bleh' OR description='bleh' GROUP BY NOT ((name=description) IS NULL AND (name=description); I think this should be more efficient than UNIONs, but am not an expert on the query planner or executor. - Stuart > -----Original Message----- > From: Mark Mikulec [SMTP:mm98au@badger.ac.brocku.ca] > Sent: Wednesday, August 15, 2001 1:41 AM > To: pgsql-sql@postgresql.org > Subject: Sequential select queries...?? > > Hello, > > At first I thought what I was trying to do was simple and could be done > easily - but alas, I've spent way too much time and could not figure out > how to get the results in question. > > Let's say I have a table T comprised of id of type integer, name and > description both of type text. > > What i'd like to do is the following: > > Select id from T where name = 'bleh'; > > and > > Select id from T where description = 'bleh'; > > and result both results in the same result set. That is, duplicate id's > if they appear. So then I could do a GROUP BY and a COUNT to see how > many appeared in only one, and how many appeared in both. > > Could someone help me? I've tried countless different sql queries, can't > seem to get one to work. If I can just get those duplicate id's in the > query.. then I'd be laughing and then I can complete my task. > > Thanks in advance, > > Mark >