Sql query to fetch result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin1983
    New Member
    • Oct 2007
    • 99

    Sql query to fetch result

    Dear All,
    How are you doing? After a long time I am back again because I need help from you all expert. Please advise me, my queries is given below.
    I have a table with employee_name which contain the field name empFirstName, empLastName, empAges, empMinExp, empMaxExp, empCTC. Etc. The employee can only select only number with out any fraction value. Like 1, 2,3, 4,5 etc. So, the problem is that when I want to fetch result by parameter min and max value of the employee I am not able to fetch the exact result. Eg.
    John Peru1 24 yrs Min: 1 yrs Max: 3 yrs 2Lacs
    John Peru2 24 yrs Min: 1 yrs Max: 3 yrs 2Lacs
    John Peru3 24 yrs Min: 1 yrs Max: 3 yrs 2Lacs
    Kin Kum 25yrs Min: 3 yrs Max: 5 yrs 3Lacs
    Dem Fu 23yrs Min: 2yrs Max: 3 yrs 4Lacs

    If, I want fetch the employee which are having minimum experience 1yrs upto 3 yrs of experience. I write the query as below,

    Select * from employee_name where empMinExp> 1 and empMaxExp<=3

    but here the query also fetch employee who entered minimum experience as 3 yrs. So, I am not able to get the exact result as per my query. Please help me in resolving the solution. Thanking you in advance for you kind cooperation and supports.

    Regards,
    Robindra Singha
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    Originally posted by robin1983
    Dear All,
    How are you doing? After a long time I am back again because I need help from you all expert. Please advise me, my queries is given below.
    I have a table with employee_name which contain the field name empFirstName, empLastName, empAges, empMinExp, empMaxExp, empCTC. Etc. The employee can only select only number with out any fraction value. Like 1, 2,3, 4,5 etc. So, the problem is that when I want to fetch result by parameter min and max value of the employee I am not able to fetch the exact result. Eg.
    John Peru1 24 yrs Min: 1 yrs Max: 3 yrs 2Lacs
    John Peru2 24 yrs Min: 1 yrs Max: 3 yrs 2Lacs
    John Peru3 24 yrs Min: 1 yrs Max: 3 yrs 2Lacs
    Kin Kum 25yrs Min: 3 yrs Max: 5 yrs 3Lacs
    Dem Fu 23yrs Min: 2yrs Max: 3 yrs 4Lacs

    If, I want fetch the employee which are having minimum experience 1yrs upto 3 yrs of experience. I write the query as below,

    Select * from employee_name where empMinExp> 1 and empMaxExp<=3

    but here the query also fetch employee who entered minimum experience as 3 yrs. So, I am not able to get the exact result as per my query. Please help me in resolving the solution. Thanking you in advance for you kind cooperation and supports.

    Regards,
    Robindra Singha
    Don't you have something basically wrong with your table structure? What do the two columns mean, empMinExp and empMaxExp? Shouldn't this instead just be one column which states the employee's experience? Why would you store an minimum and maximum value for the employee?

    A database is very powerful to deal with the data from our real world problems, and the database is most efficient and easiest to use when it's table structure correctly models our real world problem.

    Comment

    • robin1983
      New Member
      • Oct 2007
      • 99

      #3
      Originally posted by coolsti
      Don't you have something basically wrong with your table structure? What do the two columns mean, empMinExp and empMaxExp? Shouldn't this instead just be one column which states the employee's experience? Why would you store an minimum and maximum value for the employee?

      A database is very powerful to deal with the data from our real world problems, and the database is most efficient and easiest to use when it's table structure correctly models our real world problem.
      Thanks for the reply and suggestion. I really thank for the advice and I will take care from next time. But in the present scenario, what should be query, so that I can fetch only those employee which are having 1-3 yrs of experience not 3-5 yrs. please guide me.

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Originally posted by robin1983
        Thanks for the reply and suggestion. I really thank for the advice and I will take care from next time. But in the present scenario, what should be query, so that I can fetch only those employee which are having 1-3 yrs of experience not 3-5 yrs. please guide me.

        Could you please post what you have tried so far?

        Comment

        • coolsti
          Contributor
          • Mar 2008
          • 310

          #5
          I am afraid I don't understand where you are having problems.

          Let us take this example:

          One employee enters 1 for minimum experience and 3 for maximum experience.

          Another employee enters 3 for minimum experience and 5 for maximum experience.

          And you want a query that only selects the first person but not the second?

          Then the query would be

          Select * from employee_name where empMinExp> 1 and empMaxExp<=3

          This would not select the second employee above because the query states that the "empMaxExp" field must be <= 3, and the second employee above has empMaxExp = 5.

          But the Select query above is exactly the same that you showed in your original post.

          Comment

          Working...