Click to See Complete Forum and Search --> : strange query problem


raj_2006
01-11-2007, 01:37 PM
Hello,

I have a table where salary is a field with integer type.

I have values like

salary type
10000 Permanent
20000 Permanent
30000 Permanent
95000 Temporary

Now my query is like

select * from job_list where type='Temporary' or type='Contract' and salary>='10000' and salary<='30000' order by salary desc

Ihave tried this above query with BETWEEN too but still fetching 1 row where it should fetch 0 row

Please suggest as I am really astonished.

Thanks
Raj

felgall
01-11-2007, 01:45 PM
Try it like this so as to not pick up all the Temporary rows


select * from job_list where (type='Temporary' or type='Contract') and salary>='10000' and salary<='30000' order by salary desc

The AND takes priority over the OR and so your original will return values when either of the following is met:

1 type='Temporary'
2 type='Contract' and salary>='10000' and salary<='30000'

raj_2006
01-11-2007, 02:27 PM
Great.......yes you are correct....the and is getting over or

Its working now......Thanks a lot.....Luv...Raj