Re: distinct subset query

From: <vadimtro_at_gmail.com>
Date: 14 Jul 2006 14:45:16 -0700
Message-ID: <1152913516.896147.133780_at_i42g2000cwa.googlegroups.com>


Aloha Kakuikanu wrote:
> Given a relation of sets (in 1NF), return all the distinct sets.
>
> For example, given
>
> {a},{a,b},{a,b}
>
> encoded as
>
> set# element
> ---- -------
> 1 a
> 1 b
> 2 a
> 2 b
> 3 a
>
> The expected return is
>
> min
> set# element
> ---- -------
> 1 a
> 1 b
> 3 a
>
> Is it a well known query, and how to express it in SQL?

I would solve it in 3 steps:

  1. Run the set equality query for the above set relation with itself. The result

set1# set2#
----- -----
1 1
1 2
2 1
2 2
3 3

is an equivalence relation.

2. Select node(s) such that there is no node with smaller label reachable from it.

3. Join this relation with the initial set relation. Received on Fri Jul 14 2006 - 23:45:16 CEST

Original text of this message