简体   繁体   English

这个mysql查询怎么了?

[英]What is wrong with this mysql query?

Hai guys, 海人,

I ve tried a query and i dont know what is wrong with the select statement,when i execute this no records are returned... 我试过查询,但我不知道select语句出了什么问题,当我执行此操作时,没有记录返回。

It seems rollid=3 is the prob records with rollid 3 are not fetched , 似乎rollid = 3是未获取rollid为3的概率记录

select * from tbl_emp_personal_master where dEmp_id ='7'


dEmp_id is int

I even tried removing quotes from '7' to 7 it didnt help alt text http://img709.imageshack.us/img709/1901/mysqli.jpg 我什至尝试将引号从'7' to 7删除'7' to 7这对替代文本http://img709.imageshack.us/img709/1901/mysqli.jpg毫无帮助

when i repaired my table repair table tbl_emp_personal_master it started to work 当我修复表repair table tbl_emp_personal_master它开始工作

The other answers suggesting: 其他答案提示:

select * from tbl_emp_personal_master where dEmp_id = 7

should work. 应该管用。 If it doesn't, it means that the row doesn't exist in your database. 如果不存在,则意味着该行在您的数据库中不存在。 Try: 尝试:

select * from tbl_emp_personal_master where dEmp_id < 1000

and see if that returns any results. 看看是否返回任何结果。

Let's try a little debugging. 让我们尝试一些调试。 You say that 你这样说

select * from tbl_emp_personal_master where dEmp_id = '7'

doesn't work, nor does: 不起作用,也不会:

select * from tbl_emp_personal_master where dEmp_id = 7

Then you should isolate what does work. 然后,您应该隔离有效的方法。 Try each of the following: 尝试以下每种方法:

select * from tbl_emp_personal_master where dEmp_id < 10   order by dEmp_id desc
select * from tbl_emp_personal_master where dEmp_id < 100  order by dEmp_id desc
select * from tbl_emp_personal_master where dEmp_id < 1000 order by dEmp_id desc

until you get some output, then have a look at the last few lines of each where you should find employee number 7. 直到获得一些输出,然后查看每行的最后几行,您将在其中找到7号员工。

If it's not there, then you have no such employee and that's your problem. 如果不存在,那么您没有这样的员工,那就是您的问题。 If it is there, we're going to need some more investigation since your integer select of 7 should work fine in that case. 如果有,我们会需要,因为你的整数选择的7些调查应在这种情况下正常工作。


Update: Okay, with only 14 records, in the table, show us the output from: 更新:好的,表中只有14条记录,向我们显示了以下内容的输出:

select * from tbl_emp_personal_master order by dEmp_id

and we should be able to help from there. 我们应该能够从那里提供帮助。

从7中删除引号。

7 instead of '7'. 7,而不是“ 7”。 You're trying to match an int field with a charatcer. 您正在尝试将int字段与字符匹配。

Then in your 'tbl_emp_personal_master' there's no dEmp_id with the value '7'. 然后,在您的“ tbl_emp_personal_master”中,没有值为“ 7”的dEmp_id。

select dEmp_id from tbl_emp_personal_master query should tell you whether you have 7 value in the listed values in the result set. select dEmp_id from tbl_emp_personal_master查询中select dEmp_id from tbl_emp_personal_master应该告诉您结果集中列出的值中是否有7个值。 Check! 校验!

I solved it by repairing my table repair table tbl_emp_personal_master . 我通过修复表repair table tbl_emp_personal_master解决了它。 My query was executed. 我的查询已执行。 Thanks for your patience. 谢谢你的耐心。

My guess is indeed that there is no record having the dEmp_id field set to 7. 我的猜测确实是没有dEmp_id字段设置为7的记录。

  select * from tml_emp_personal_master where dEmp_id between 6 and 8

should allow to check this. 应该允许对此进行检查。

Regarding the enclosure of the field, it depends on your DBMS. 关于字段的外壳,取决于您的DBMS。 Enclosing numeric values in MySQL is perfectly legal and even recommended (cf chapter about SQL injections and numeric values). 在MySQL中包含数字值是完全合法的,甚至是推荐使用的 (请参阅有关SQL注入和数字值的章节)。

Regarding what is wrong , it is generally recommended not to use select * but to list all required fields for performance and readability purposes. 关于出了什么问题 ,通常建议不要使用select *,而是为了性能和可读性列出所有必填字段。

Also, if the query is ran from a programming language, it is strongly adviced to use parameterized queries if available (for instance DBParameter in .Net, PDO in PHP etc). 另外,如果查询是从编程语言运行的,则强烈建议使用可用的参数化查询(例如,.Net中的DBParameter,PHP中的PDO等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM