-1

I need to get the common string between 2 fields:

enter image description here

Could I do it in sql (postrgre) ?

PS :It's an hypothetical pourcentage that's gives me the similarity of fields s2 and s2

Thank you in advance,

betty
  • 59
  • 9
  • You could do it by looking at the percentage of (length now versus length before) if you "replace in str1, find str2, replacewith nothing" and do the same the other way round.. but what is you algorithm for deriving the percentage similarity there? – Caius Jard Apr 27 '20 at 04:44
  • clarification: Do you mean select by the common string, or use a query, and find the common string between them? – Robert Mennell Apr 27 '20 at 04:46
  • How aer those percentages calculated? – Andronicus Apr 27 '20 at 04:50
  • Actually I need just to know if the 2 fields are common, mean they are actually the same, otherwise, get the pourcentage of common variables between the 2 fields. i don't know if I'm clear .. – betty Apr 27 '20 at 04:55
  • sadly it's not very clear. You'll need to clarify it a bit more so that it makes sense in a way we can answer. – Robert Mennell Apr 27 '20 at 13:44

1 Answers1

0
select * from table where field ilike $1;

More information on ilike however be warned that without an index or some sort of way to make the search faster, this is going to be a SLOW crawl over the table and it's values.

There are more advanced matching you can do. It would still be recommended to filter down your results set and then do the match against it somehow.

You would probably do that by matching on something smaller to compare to and then doing the matching for the string, but these links should be exactly what you're looking for.

Robert Mennell
  • 1,954
  • 11
  • 24
  • Thank for the suggestion, it works for the exact same fileds, but what's I need it to get also the one that doesn't match but have a common characters :( – betty Apr 27 '20 at 05:06