Results 1 to 10 of 10

Thread: Difference between BETWEEN and AND query?

  1. #1
    Moderator
    Join Date
    Sep 2006
    Answers
    920

    Difference between BETWEEN and AND query?

    i write a query

    select * userid from users where userid between 1000 and 3000;

    now i write another query

    select * userid from users where userid > 1000 and userid <3000;

    What is the difference b/w both query?

    Regards,
    Brijesh Jain
    ---------------------------------------------------------
    Connect with me on Skype: jainbrijesh
    Google Plus : jainbrijeshji

  2. #2
    Expert Member
    Join Date
    Dec 2006
    Answers
    204

    Re: Difference between BETWEEN and AND query?

    No difference at all. between and is the alternative for your second query.


  3. #3
    Moderator
    Join Date
    Sep 2006
    Answers
    920

    Re: Difference between BETWEEN and AND query?

    Quote Originally Posted by Barbie View Post
    No difference at all. between and is the alternative for your second query.
    Barbie you say there is no difference but when i executed these queries i got different results.
    theoretically there is no difference , but practically we get different query result, what a joke it is ?

    Last edited by jainbrijesh; 04-30-2007 at 08:51 AM.
    Regards,
    Brijesh Jain
    ---------------------------------------------------------
    Connect with me on Skype: jainbrijesh
    Google Plus : jainbrijeshji

  4. #4
    Junior Member
    Join Date
    May 2007
    Answers
    11

    Lightbulb Re: Difference between BETWEEN and AND query?

    Hi

    There is difference between the two queries.

    wen u use BETWEEN, both the values are inclusive in the search criteria.
    whereas this is not the case in your second query.
    for both the queries to return same results, use >= and <= instead of > and <


  5. #5
    Moderator
    Join Date
    Sep 2006
    Answers
    920

    Re: Difference between BETWEEN and AND query?

    Quote Originally Posted by rishamjeet View Post
    Hi

    There is difference between the two queries.

    wen u use BETWEEN, both the values are inclusive in the search criteria.
    whereas this is not the case in your second query.
    for both the queries to return same results, use >= and <= instead of > and <
    Yes friend,
    You are right.
    Same happens when we do it practically.

    Regards,
    Brijesh Jain
    ---------------------------------------------------------
    Connect with me on Skype: jainbrijesh
    Google Plus : jainbrijeshji

  6. #6
    Expert Member
    Join Date
    Dec 2006
    Answers
    204

    Re: Difference between BETWEEN and AND query?

    yeah. its right. i am sorry.


  7. #7
    Contributing Member
    Join Date
    Apr 2007
    Answers
    46

    Re: Difference between BETWEEN and AND query?

    Hi, you can see the difference with following example:- sql> select * from student1; name dept salary ---------- ---------- ---------- reeta dm 10000 reeta dm 20000 reeta dm 30000 reeta dm 400000 sql> select * from student1 where salary between 10000 and 30000; name dept salary ---------- ---------- ---------- reeta dm 10000 reeta dm 20000 reeta dm 30000 sql> select * from student1 where salary>10000 and salary<30000; name dept salary ---------- ---------- ---------- reeta dm 20000 it means between function give us back the 10000 and 30000 values also rather than on 20000 which is greater than 10000 but less than 30000; i hope this work for you reeta


  8. #8
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: Difference between BETWEEN and AND query?

    Another difference is, as BETWEEN-AND pair is a SQL clause of the command it works faster.

    If a combination of comparison and logical operators are used in a query, the query runner will have to construct the query evaluation program and then apply the given criteria and boundaries in the evaluation program. Where as if a BETWEEN-AND pair is used, it has to only apply boundaries and extract rows from the tale.

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

  9. #9
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Difference between BETWEEN and AND query?

    dear friends

    BETWEEN is a range operator .which is used to check for a range of values. recomended to use only with number and date datatype.

    AND is a logical operator, which is used to logically concadinate more than one conditions.


  10. #10
    Junior Member
    Join Date
    Jun 2007
    Answers
    18

    Re: Difference between BETWEEN and AND query?

    Between- It returns data between two sets of values
    eg:between 10 AND 20 mean returns data between 10 and 20 inclucing 10 and 20
    AND:and returns value when two conditions are satisfied


  11.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact