MySQL查询结果有些奇怪 [英] mysql query result in something weird

查看:48
本文介绍了MySQL查询结果有些奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...我只是想问为什么我的查询听起来很奇怪?您设置了我刚刚创建的查询,该查询将根据ID号搜索结果,但是当我的查询生成结果时,我感到惊讶,因为它返回了结果...这是我的查询

Hi guys... i just want to ask why is it that my query is acting weird? you set i just created a query that will search a result based on the id number but when my query generated a result i was surprised because it returned a result... heres my query

SELECT id,name,status from tbl_priviledge where  id >= ''sdfasdfasdf'' LIMIT 0, 2



我原本希望返回空结果,但它返回了一个结果...我知道没有ID的值为



i was expecting to return an empty result but it returned a result... which i know there is no id with a value of

''sdfasdfasdf''

,所以我该如何解决呢?

so how do i fix this?

推荐答案

在查询中使用输入之前,应先对其进行验证.

MySQL有一些比较不同类型的规则,这解释了为什么"sdfasdfasdf"的求值为0:
http://dev.mysql.com/doc/refman/5.5/en/type- conversion.html [^ ]
You should validate your inputs before you use them in queries.

MySQL has some rules for how it compares different types, which explains why ''sdfasdfasdf'' evaluates as 0:
http://dev.mysql.com/doc/refman/5.5/en/type-conversion.html[^]


不要使用> ="-请使用"="代替:
Don''t use ">=" - use "=" instead:
SELECT id,name,status from tbl_priviledge where  id >= 'sdfasdfasdf' LIMIT 0, 2

成为

SELECT id,name,status from tbl_priviledge where  id = 'sdfasdfasdf' LIMIT 0, 2

SQL可以比较字符串和数字...

SQL can compare strings asa well as numbers...


如果您要测试不平等性(即您不想搜索id =" sdfasdfasdf"),请使用<>而不是> =.我认为SQL使用单个字母的ascii值比较字符串值.因此,任何以大于"s"的字符(即t,u,v,...,z)开头的字符都被视为大于以"s"开头的字符串

或者您可以使用:

If you want to test for inequility, (i.e. you don''t want to search for id = ''sdfasdfasdf'') use <> instead of >=. I think the SQL compares the string values using the ascii values of the individual letters. So anything starting with a character bigger than ''s'' (i.e. t,u,v,...,z) is considered larger than the strings that start with ''s''

Or you can use:

SELECT id,name,status from tbl_priviledge where NOT (id = 'sdfasdfasdf') LIMIT 0, 2


这篇关于MySQL查询结果有些奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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