如何在 SQL 中进行精确的字符串匹配 [英] How to do exact string match in SQL

查看:55
本文介绍了如何在 SQL 中进行精确的字符串匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表 PC 和 PC/name 中有两个值.但是当我写一个查询时,

I have two values in table PC and PC/name. But when I write a query,

select * from TransDetail TD where td.ModUserId like '%PC/%'

它给了我两个结果.有没有办法只得到一个记录?

it gives me both results. Is there a way to get only one record?

推荐答案

你应该让你的 WHERE 子句像这样:

You should make your WHERE clause like this:

select * 
from TransDetail TD
where TD.ModUserId ='PC'

这样您将获得与PC"匹配的结果.
你所做的喜欢是给出你的情况的结果,PC可以是领域的开始/中间/结束

This way you will get the results which are matched to 'PC' only.
The like that you made is giving your results of cases that PC can be start/middle/end of the field

这篇关于如何在 SQL 中进行精确的字符串匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆