• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

19. Some Common Data Manipulation Problems > 19.10. Equality of Sets

Equality of Sets

A common problem is determining when two sets are equal, that is, when they have the same elements. Consider Table 19-20, which shows five sets and their members. To simplify this as much as possible, we simply number the sets and assume they contain numbers themselves. We want to get a list of which sets are equal.

Table 19-20. Equality

Set

Member

1

1

1

2

1

3

2

1

2

2

2

3

3

1

3

2

3

3

3

4

4

1

4

2

4

3

4

4

5

1

5

2

5

8

Solution

This problem has an elegant solution using a single SQL statement. While, in general, SQL does not permit us to compare two sets directly, as in:

(SELECT Members FROM Equality WHERE Set=1) = (SELECT Members FROM Equality WHERE _
  Set=2)

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint