1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

How can I find fields that have a substring in common?

Discussion in 'SQL - Questions and Answers' started by stav, Oct 16, 2006.

  1. stav New Member

    Dialect: SQL 92
    for example :
    the records "a substring b" and "substring c d" would be a match, and so would "xxx" "aa xxx" etc. If possible: I'd like returned the substring, or the indexes of it's beginning and end in one of the strings.
  2. Dimitar Guest

    Dialect: SQL 92
    SQL:

    select t0.s from t t0 , t t1 where position(t0.s in t1.s) <>0 group by t0.s having count(*) > 1

    A quick answer based on the idea that you join a table with itself to produce a t^2 from which you select only those who have something in common. The grouping and the having clause are used to filter out rows produced by a row with itself.
  3. Dimitar Guest

    My previous answer
    SQL:

    SELECT t0.s FROM t t0 , t t1 WHERE position(t0.s IN t1.s) <>0 GROUP BY t0.s HAVING count(*) > 1

    obviously does not fullfill the requirements.
  4. diego Guest

    Dialect: T-SQL
    use the "like" comand
    SQL:

    SELECT string FROM table where string like '%' + @substringTocompare + '%'



    where the special character '%' is a comodin for find all substring similary.

Share This Page