Sammy Guergachi
Sammy Guergachi

Reputation: 2006

Fuzzy Matching in H2 Database?

I was just wondering if there was a simple way to implement Fuzzy matching of strings using the H2 Database. I have in the database a list of names and I want to be able to search through them using 3 characters that may be found anywere in the name in the order the 3 characters are typed in.

i'm not sure if that's even possible to do, but it would make life much easier if it were possible to be done in the database via SQL and not Java

Upvotes: 1

Views: 1910

Answers (1)

Thomas Mueller
Thomas Mueller

Reputation: 50097

You could use

select * from test where name like '%xyz%'

See also the documentation of LIKE.

Another option is to use SOUNDEX:

select * from test where soundex(name) = soundex('word')

In both cases, an index can not be used. That means the query is slow if there are many rows in the table, as each row must be checked.

Upvotes: 2

Related Questions