www.webdeveloper.com
Results 1 to 3 of 3

Thread: strange query problem

  1. #1
    Join Date
    Feb 2006
    Location
    india
    Posts
    680

    strange query problem

    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

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    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'
    Last edited by felgall; 01-11-2007 at 12:48 PM.
    Stephen

  3. #3
    Join Date
    Feb 2006
    Location
    india
    Posts
    680
    Great.......yes you are correct....the and is getting over or

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles