Hello,

I'm not Joe Celko myself so I've found a solution that's somewhat crappy but
that work for your precise question

here is the complete script (tested in MSSQL)
--=============================
create table #TempItems
(
 [DocumentId] [int],
 [Characteristic] [varchar] (1)
)
insert into #TempItems([DocumentId] , [Characteristic])
values(1,'a')
insert into #TempItems([DocumentId] , [Characteristic])
values(1,'b')
insert into #TempItems([DocumentId] , [Characteristic])
values(1,'d')
insert into #TempItems([DocumentId] , [Characteristic])
values(2,'a')
insert into #TempItems([DocumentId] , [Characteristic])
values(3,'a')
insert into #TempItems([DocumentId] , [Characteristic])
values(3,'b')
select * from #tempitems

select distinct([table1].[documentid])
from #Tempitems as [table1], #TempItems as [table2], #TempItems as [table3]
where [table1].[DocumentId] = [table2].[DocumentId]
and [table1].[DocumentId] = [table3].[DocumentId]
and [table1].[Characteristic] = 'a'
and [table2].[Characteristic] = 'b'
and [table3].[Characteristic] = 'd'
group by [table1].[DocumentId]
drop table #tempitems
--=============================

This solution is crappy because you need to create as many alias as you need
matching charateristics.

Maybe someone else have a better solution wich will be more interesting

Gauthier

----- Original Message -----
From: "Bill Conlon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 10, 2003 6:03 PM
Subject: Witango-Talk: OT: SQL help


> I picked my SQL in the street, so it's kind of rudimentary.  Maybe
> someone can point me in the right direction.
>
> Here's a table
>
> document  characteristic
> 1         a
> 1         b
> 1         d
> 2         a
> 2         d
> 2         e
> 3         a
> 3         b
>
> I want to SELECT the document(s) that match all of a set of
> characteristics.
>
> Say I want all documents with characteristic a AND b:  This should return
> documents 1 and 3
>
> Likewise, requesting characteristics a AND d returns documents 1 and 2
>
> Say I request characteristics b AND d:  I should get no rows.
>
> thanks
>
> Bill Conlon
>
> To the Point
> 345 California Avenue Suite 2
> Palo Alto, CA 94306
>
> office: 650.327.2175
> fax:    650.329.8335
> mobile: 650.906.9929
> e-mail: mailto:[EMAIL PROTECTED]
> web:    http://www.tothept.com
>
>
> ________________________________________________________________________
> TO UNSUBSCRIBE: Go to http://www.witango.com/maillist.taf
> _____________________________________________________________________
> Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
> http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/maillist.taf

Reply via email to