Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:12:11+00:00 2026-05-31T15:12:11+00:00

say if the table trap has column ‘id’ and rows contents as 7 8

  • 0

say if the table trap has column ‘id’ and rows contents as

7
8
9
10
11
12
13
14

SELECT id FROM trap
WHERE id<10 and id>12

this doesn’t give any output

but if

SELECT id FROM trap
WHERE id>7 and id<14

give me the required output i.e.,

8
9
10
11
12
13
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:12:12+00:00Added an answer on May 31, 2026 at 3:12 pm

    The problem is that you’re using the AND operator where you should be using OR.

    SELECT id FROM trap WHERE id<10 OR id>12
    

    Obviously id cannot be both 10 AND 12 at the same time, one box can only hold one value.

    Alternatively you can write the statement as:

    SELECT id FROM trap WHERE NOT(id BETWEEN 10 AND 12) 
    

    The reason that SELECT id FROM trap WHERE id>7 and id<14 does work is that it is possible for a value to be BETWEEN 8 AND 13 (inclusive) at the same time.
    However no way can a value ever the smaller than 10 and larger than 12 at the same time.

    So if the conditions are mutually exclusive you must use OR, if the conditions do not exclude one and other then you must use AND.
    You can wrap a test inside a NOT() to reverse the test, this is because AND and OR are exact opposites.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say a table has several subclass types. How can I see all columns from
I have two tables with similar columns - let's say table A with column
I have this problem where after a field (say Field3 in table MyTable) is
Say I have an MSSQL table with two columns: an int ID column that's
I have a table say something like this: column_a column_b foo 1 bar 1
I am using sql server 2005 I have a table [say tblHistory] and this
I would like to copy data from an existing table say table1 to a
Say I have Table A that has many Table B's. Table B has only
I need to copy over rows from Table B to Table A. The requirement
Lets say a table like this (just for illustration): KEY VALUE 1 A 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.