Re: Sequential select queries...??

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
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 16:39:42
Message-ID: web-105146@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mark,

> 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.

What you want is UNION ALL. You also want to go out and purchase "SQL
for Smarties" after you finish reading my e-mail.

SELECT id FROM T WHERE name = 'bleh'
UNION ALL
SELECT id FROM T WHERE description = 'bleh';

This gives you both result sets, once right after the other. If you
didn't want to see duplicate values (i.e. only one instance of each
"id"), you would use simply UNION without the "ALL".

This means that it is possible to get both your desired rowcounts out of
a *single* query, using subselects. "SQL for Smarties" can help you
learn to build this kind of query.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ross J. Reedstrom 2001-08-20 17:09:43 Re: Sequential select queries...??
Previous Message Robby Slaughter 2001-08-20 16:35:00 RE: Sequential select queries...??