Results 1 to 3 of 3

Thread: sql set theory question

  1. #1
    Join Date
    Mar 2011
    Posts
    1

    sql set theory question

    ok, this is probably something i would have figured out pretty quickly back in computer science school. but that was a long time ago and work has made me stupid.
    here's the problem.

    i have a set of tuples - {code,token}

    every code points to a set of tokens.
    some of the codes point to the same tokens.

    the object is to find the sets of codes that share sets of tokens, where the cardinality of the set of shared tokes is > 1

    i have a truly ugly recursive brute force solution written in c# but it just seems like there ought to be an elegant simple bit of sql which will yield the same results. sadly, it has yet to occur to me. pretty sure this is going to take somebody several seconds to solve.
    thanks,
    garth

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Take look at 'Recursive Queries Using Common Table Expressions' in sql server books online.

  3. #3
    Join Date
    Sep 2005
    Posts
    168
    could it be that simple?
    select code
    from tuples
    group by code
    having count(distinct token) > 1

    --HTH--

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •