SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 10-16-2006, 07:17 PM
stav stav is offline
Junior Member
 
Join Date: Oct 2006
Posts: 2
stav is on a distinguished road
Default SQL 92 dialect question:

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 10-18-2006, 03:54 AM
Dimitar
 
Posts: n/a
Default SQL 92 answer. Re: How can I find fields that have a substring in common?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-29-2006, 05:25 AM
Dimitar
 
Posts: n/a
Default ANY answer. Re: How can I find fields that have a substring in common?

My previous answer
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-06-2007, 03:30 AM
diego
 
Posts: n/a
Default T-SQL answer. Re: How can I find fields that have a substring in common?

use the "like" comand
SELECT string FROM TABLE WHERE string LIKE '%' + @substringTocompare + '%'


where the special character '%' is a comodin for find all substring similary.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:41 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8