🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.listserv.sqlinfo
Article #239

Re: Help joining table attributes...

#239
From: Mads Brenoe
Date: Sat, 26 Aug 2000 00:00
44 lines
1813 bytes
you should be able to do what you want, by combining two selection
formulas with IN. the query bolow should do the trick

select id
from table
where keyname = 'c'
and id IN (
select id
from table
where keyname = 'a'
or keyname = 'b')



Shawn Hughes wrote:
> 
> How do you group attributes from one table
> and 'OR' the elements from one group and
> 'AND' the sets of results.  For example...
> 
> table tab1(index keyname)
> keyname     group
> a                          1
> b                          1
> c                          2
> 
> table tab2 (index id, keyname)
> id                    keyname
> 1001                    a
> 1002                    a
> 1002                    c
> 1003                    b
> 1003                    c
> 1004                    c
> 
> My query is "Give me the articles which have (either attribute
> 'a' or attribute 'b') AND attribute 'c'.
> 
> Based on this set, I need to select id=1002 (because it has both
> 'a' and 'c' attributes) and id=1003 ('b' and 'c').
> 
> Any pointers would be appreciated.
> 
> Shawn.
Technical Details
Message-ID: <39A81A3B.DCB5A49@hjortespring.dk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <39987A56.6F85CFC4@jpmorgan.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11355a,cffead133f4a2969
X-Google-Attributes: gid11355a,public
From: Mads Brenoe <mb1104@hjortespring.dk>
Subject: Re: Help joining table attributes...
Date: 2000/08/26
Message-ID: <39A81A3B.DCB5A49@hjortespring.dk>
X-Deja-AN: 663191644
Content-Transfer-Encoding: 7bit
References: <39987A56.6F85CFC4@jpmorgan.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: usenet@news.net.uni-c.dk
X-Trace: news.net.uni-c.dk 967401200 13762 194.182.124.202 (27 Aug 2000 18:33:20 GMT)
Organization: UNI-C
Mime-Version: 1.0
NNTP-Posting-Date: Sun, 27 Aug 2000 18:33:20 +0000 (UTC)
Newsgroups: bit.listserv.sqlinfo