Re: Sequential select queries...??

From: "Jeff Eckermann" <jeckermann(at)verio(dot)net>
To: "Mark Mikulec" <mm98au(at)badger(dot)ac(dot)brocku(dot)ca>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Sequential select queries...??
Date: 2001-08-20 17:28:34
Message-ID: 00d201c1299d$8aa57cb0$279c10ac@INTERNAL
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Select id from T where name = 'bleh'
UNION ALL
Select id from T where description = 'bleh';

Will get you the resultset you want, but: I don't believe that you can do a
GROUP BY on it.
If you just want counts, as you describe below, you could do something like:

SELECT 'Only One', (SELECT count (id) from T where name = 'bleh' OR
description = 'bleh') - (SELECT count (id) from T where name = 'bleh' AND
description = 'bleh')
UNION
SELECT 'Both', (SELECT count (id) from T where name = 'bleh' AND description
= 'bleh');
----- Original Message -----
From: "Mark Mikulec" <mm98au(at)badger(dot)ac(dot)brocku(dot)ca>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Tuesday, August 14, 2001 7:40 PM
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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Grigoriy G. Vovk 2001-08-20 17:43:17 Re: Sequential select queries...??
Previous Message Stephan Szabo 2001-08-20 17:11:02 Re: Strange DISTINCT !