'=' 和有什么区别?不使用通配符时的运算符和 LIKE
我做这个问题是因为我找不到具有相同原因的问题。原因是当我使用 LIKE
时,我得到一致的结果,而当我使用 (=) 运算符时,我得到不一致的结果。
案例
我有一个大视图(viewX),具有多个内部联接和左联接,其中某些列具有空值,因为数据库定义允许这样做。
- 当我打开此视图时,我看到例如:结果为 8 行。
- 例如,当我运行:
select * from viewX where column_int = 34 and type_string = 'xyz'
时,此查询向我显示 100 行,这些行未在视图结果中定义。 [不一致]
但是
- 当我运行
select * from viewX where column_int = 34 and type_string like 'xyz'
时,此查询仅显示 4 行,这是我打开时在视图中定义的(请参阅 1. )[一致]
有人知道这里发生了什么吗?
I do this question, because I can't found a question with the same reason. The reason is when I use LIKE
, I get CONSISTENT RESULTS, and when I use (=) operator I get INCONSISTENT RESULTS.
THE CASE
I have a BIG VIEW (viewX) with multiple inner joins and left joins, where some columns have null values, because the database definition allows for that.
- When I open this VIEW I see for example: 8 rows as result.
- When I run for example:
select * from viewX where column_int = 34 and type_string = 'xyz'
, this query shows me 100 rows, that aren't defined in the result of the view. [INCONSISTENT]
BUT
- When I run
select * from viewX where column_int = 34 and type_string like 'xyz'
, this query show me only 4 rows, that is defined in the view when I opened (see 1.) [CONSISTENT]
Does anyone idea, of what is happening here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从文档中......
“根据 SQL 标准,LIKE 在每个字符的基础上执行匹配,因此它可以产生与 = 比较运算符不同的结果:”
更重要的是(使用 LIKE 时):
“字符串比较不区分大小写,除非操作数之一是二进制字符串',
来自:
http://dev.mysql.com/doc/refman /5.0/en/string-comparison-functions.html
From the documentation.....
'Per the SQL standard, LIKE performs matching on a per-character basis, thus it can produce results different from the = comparison operator: '
more importantly (when using LIKE):
'string comparisons are not case sensitive unless one of the operands is a binary string'
from :
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
根据 MySQL 文档
LIKE
的功能与=
不同,尤其是当尾随或前导空格时。您需要发布您的实际查询,但我猜它与已知的差异有关。
Per the MySQL documentation
LIKE
does function differently than=
, especially when you have trailing or leading spaces.You need to post your actual query but I'm guessing it's related to the known variances.