Path: text.usenetserver.com!out01a.usenetserver.com!news.usenetserver.com!in02.usenetserver.com!news.usenetserver.com!postnews.google.com!p39g2000hse.googlegroups.com!not-for-mail
From:  David Portas <REMOVE_BEFORE_REPLYING_dportas@acm.org>
Newsgroups: comp.databases.theory
Subject: Re: difference between UNION operator and OR in where clause
Date: Tue, 10 Jul 2007 06:59:09 -0700
Organization: http://groups.google.com
Lines: 37
Message-ID: <1184075949.760634.199510@p39g2000hse.googlegroups.com>
References: <1184074770.394660.52860@d55g2000hsg.googlegroups.com>
NNTP-Posting-Host: 86.155.213.170
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
X-Trace: posting.google.com 1184075949 10902 127.0.0.1 (10 Jul 2007 13:59:09 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 10 Jul 2007 13:59:09 +0000 (UTC)
In-Reply-To: <1184074770.394660.52860@d55g2000hsg.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: p39g2000hse.googlegroups.com; posting-host=86.155.213.170;
   posting-account=GH1roQ0AAACgftr1B9S4n3XwqdsCU7E1
Xref: usenetserver.com comp.databases.theory:165690
X-Received-Date: Tue, 10 Jul 2007 09:59:10 EDT (text.usenetserver.com)

On 10 Jul, 14:39, Mike <gongweig...@gmail.com> wrote:
> tables:
> 1. publication(pubid, title)
> 2. book(pubid, date)
> 3. journal(pubid, date)
>
> purpose: find all publication titles for books or journals.
>
> solution 1: use set "union"
>
> select title
> from publication, ( (select pubid from book) UNION (select pubid from
> journal)) bj
> where publication.pubid = bj.pubid
>
> solution 2: use "or" operator in the where clause
>
> select title
> from publication, book, journal
> where publication.pubid = book.pubid or publication.pubid =
> journal.pubid
>
> This example is taken from some lecture notes about sql. The notes
> said the solution 2 was wrong.
>
> Anyone knows why ?
>

Let me pose two more questions for you. What are the keys for each
table? What is the difference between ALL and DISTINCT?

If you can answer those questions then you may be on the way to the
answer you are looking for.

--
David Portas

