Re: How to use DISTINCT for two attributes combined

From: Lennart Jonsson <lennart_at_kommunicera.umea.se>
Date: 28 Jul 2003 09:59:20 -0700
Message-ID: <6dae7e65.0307280859.50de6179_at_posting.google.com>


"Xiaoxin Yin" <xyin1_at_uiuc.edu> wrote in message news:<I12Va.4195$o7.54409_at_vixen.cso.uiuc.edu>...
> Hi,
>
> I want to select the count of distinct tuples in a table for some query. For
> example,
> select count(distinct A.a1, A.a2) from FirstRel A, SecondRel B where
> A.a3=B.b1 group by B.b2, B.b3
> (Suppose FirstRel.a1 and FirstRel.a2 is the primary key of FirstRel.)
>
> However, it is not recognized by sql server. Is there any way that I can get
> the count of distinct tuples in A?
>
> Thanks a lot,
>

You might try:

select count(1) from (

    select distinct A.a1, A.a2 from FirstRel A, SecondRel B     where A.a3=B.b1
) X (a1, a2)

HTH
/Lennart

--
the above email no longer works due to spam.
values'lennart'||CHR(46)||'jonsson'||CHR(64)||'enlight'||CHR(46)||'net'
Received on Mon Jul 28 2003 - 18:59:20 CEST

Original text of this message