views:

108

answers:

7

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...

It seems rollid=3 is the prob records with rollid 3 are not fetched,

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 helpalt text

when i repaired my table repair table tbl_emp_personal_master it started to work

+1  A: 

Remove the quotes from the 7.

Tor Valamo
@Tor it didnt help
Saranya
It's the only thing that's "wrong" with that statement.
Tor Valamo
You may want to "select * from tbl" to make sure that the id 7 actually exists...
Tor Valamo
+1  A: 

7 instead of '7'. You're trying to match an int field with a charatcer.

Deep-B
@Deep it didnt help
Saranya
+3  A: 

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.

Mark Byers
i tried the second one it worked , i dont know it is very strange that it takes upto 6 empids but not 7
Saranya
@Sarnya, are you saying that the "< 1000" version showed you employee number 7?
paxdiablo
ya paxdiablo but i didnt get records when i give = symbol
Saranya
see my edited portion
Saranya
+3  A: 

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.

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.


Update: Okay, with only 14 records, in the table, show us the output from:

select * from tbl_emp_personal_master order by dEmp_id

and we should be able to help from there.

paxdiablo
@paxdiablo my table contains 14 records i can get records upto 6 th one but from 7 th icant get when i give a where condition
Saranya
See the update. The table is tiny so, if you show us the whole thing, it should be easier to pinpoint the problem.
paxdiablo
@paxdiablo see the screen shot above
Saranya
+1 just for the helpful/kind language. :)
Bart J
A: 

Then in your 'tbl_emp_personal_master' there's no dEmp_id with the value '7'.

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. Check!

Sandeep
Correct Answer!?
Sri Kumar
A: 

My guess is indeed that there is no record having the dEmp_id field set to 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. Enclosing numeric values in MySQL is perfectly legal and even recommended (cf chapter about SQL injections and numeric values).

Regarding what is wrong, it is generally recommended not to use select * but to list all required fields for performance and readability purposes.

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).

Benoit Vidis
+1  A: 

Hai guys,

I solved it by repairing my table repair table tbl_emp_personal_master . My query was executed.. Thanks for ur patience response...

Saranya