pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Frank Morton <fmorton@base2inc.com>
To: pgsql-sql@postgresql.org
Subject: join question
Date: Fri, 18 Oct 2002 13:58:13 -0500
Message-ID: <027d01c276d8$504a1100$8455e5ce@edison> (raw)
References: <F53s0dt2NCF6TMlz9K90000565d@hotmail.com>

For the SQL gurus, a query where I'm not getting the expected
results. Trying to write it using sql compatible with both postgres
and mysql.

There are two tables:

table = profile
int id
char name

table = attribute
int id
int containerId
char name
char value

Multiple attribute rows correspond to a single profile row where
attribute.containerId = profile.id

These two queries result in one row being returned, which is
the expected result:

select name from profile where ((profile.state='1020811'));

select profile.name from profile,attribute where (((attribute.name='description') and (attribute.value='1020704') and (profile.id=attribute.containerId)));

But, I thought this next query would just be a simple way to combine the two
queries with an "or" operator, still returning one row, actually returns
ALL rows of attribute:

select profile.name from profile,attribute where ((profile.state='1020811') or ((attribute.name='marketsegment') and (attribute.value='1020704') and (profile.id=attribute.containerId)));

Why doesn't this last query return just one row?

TIA

view thread (22+ messages)  latest in thread

Message-ID: <027d01c276d8$504a1100$8455e5ce@edison>
Permalink:  ../027d01c276d8$504a1100$8455e5ce@edison/
Also on:    postgresql.org/message-id/027d01c276d8$504a1100$8455e5ce@edison

 · 

reply

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: fmorton@base2inc.com
  Subject: Re: join question
  In-Reply-To: <027d01c276d8$504a1100$8455e5ce@edison>

* 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