两个字符串mysql之间的区别

时间:2014-02-21 10:29:41

标签: mysql string difference

我想找到MySQL中两个字符串之间的区别。比如,如果输入了像nishant和nisha这样的两个字符串,则应输出'nt'。

1 个答案:

答案 0 :(得分:1)

set @string2 :="nishant";
Query OK, 0 rows affected (0.00 sec)

set @string1 := "nisha";
Query OK, 0 rows affected (0.00 sec)

select @string1, @string2;
+----------+----------+
| @string1 | @string2 |
+----------+----------+
| nisha    | nishant  |
+----------+----------+
1 row in set (0.00 sec)

select if(length(@string1)>length(@string2), replace(@string1, @string2,""), replace(@string2, @string1, "")) as "The Difference";
+----------------+
| The Difference |
+----------------+
| nt             |
+----------------+
1 row in set (0.00 sec)
相关问题