mingzhao.pro
mingzhao.pro

Reputation: 759

How to compare two String in mysql

I need update my db data and the condition is to compare the old and new value.

The problem is the new value is a longer string containing the old value at db and I cannot find a way to compare them by a function like A contains B which A is new value and B is the old one at my db.

And I dont want to read the value from DB and compare by Java then if it matches, update the value. I think that will be heavy for treating a million rows.

Upvotes: 0

Views: 307

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

You can use like:

where newvalue like concat(oldvalue, '%')

or

where newvalue like concat('%', oldvalue, '%')

The difference is whether the new value needs to start with the old value or just contain it anywhere.

Upvotes: 1

Related Questions