From: Josh Berkus <josh@agliodbs.com>
To: Mark Mikulec <mm98au@badger.ac.brocku.ca>
To: pgsql-sql@postgresql.org
Subject: Re: Sequential select queries...??
Date: Mon, 20 Aug 2001 09:39:42 -0700
Message-ID: <web-105146@davinci.ethosmedia.com> (raw)
In-Reply-To: <3B79C512.9F6E09B7@badger.ac.brocku.ca>
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@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, mm98au@badger.ac.brocku.ca
Subject: Re: Sequential select queries...??
In-Reply-To: <web-105146@davinci.ethosmedia.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox