CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Posts
    73

    Perform advanced searches in SELECT statement

    Hello all
    I wanted to ask if there is a way of inserting some mathematics in an SQL select statement.
    What I am interested in is to select all rows from a table where 56<ID<67 for example.

    Thank you

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Perform advanced searches in SELECT statement

    I suggest to do some tutorials about sql. A good one can be found on w3schools.com

    The part you are looking for: http://w3schools.com/sql/sql_between.asp

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Perform advanced searches in SELECT statement

    Yes there is a way to perform almost every kind of search using SQL, the only condition for that is you should go through some tutorials and do some practice.

  4. #4
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,901

    Re: Perform advanced searches in SELECT statement

    SO THE TUTORIAL LINK GIVEN SHOWS YOU ...

    Code:
    SELECT column_name(s)
    FROM table_name
    WHERE column_name
    BETWEEN value1 AND value2
    Another way could also be

    Code:
    SELECT * FROM table_name
    WHERE ID > 56 AND ID < 67

  5. #5
    Join Date
    May 2009
    Location
    Lincs, UK
    Posts
    298

    Re: Perform advanced searches in SELECT statement

    The difference is that
    Code:
    column_name BETWEEN value1 AND value2
    includes both value1 and value2, so to get the rows such that 56 < ID < 67 (that is not including 56 and 67) you need to use either George1111's alternative or
    Code:
    ... WHERE ID BETWEEN 57 AND 66

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured