| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
How can I find fields that have a substring in common?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. |
|
|||
SELECT t0.s FROM t t0 , t t1 WHERE position(t0.s IN t1.s) <>0 GROUP BY t0.s HAVING count(*) > 1A 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. |