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 7502737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:58:24+00:00 2026-05-29T20:58:24+00:00

I would like to insert a new price range in a table but before

  • 0

I would like to insert a new price range in a table but before I need to check if my price range is already included or part of any other price range.

Here is an example:

My price range table:

| minimum | maximum |
---------------------
|       1 |     100 |
|     201 |     300 |
|     301 |     400 |
  • If I submit [50,200], I must reject it because 50 is included in the range [1,100].
  • If I submit [175,201], I must reject it because 201 is included in the range [201,300].
  • If I submit [350,380], I must reject it because 350 and 380 are included in the range [301,400].
  • If I submit [120,190], I must accept it because 120 and 190 are not included in any range.

My question is how to check with MySQL if the submitted range is included or not in my table.

  • 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-29T20:58:25+00:00Added an answer on May 29, 2026 at 8:58 pm

    This should work (assuming the table is called ranges and the new range parameters are @low and @high respectively):

    IF(NOT EXISTS (SELECT *
                     FROM ranges
                    WHERE @low BETWEEN minimum AND maximum)
       AND 
       NOT EXISTS (SELECT *
                     FROM ranges
                    WHERE @high BETWEEN minimum AND maximum))
    BEGIN
         INSERT INTO ranges
             (minumum, maximum)
           VALUES
             (@low, @high)
    END
    

    Of course, this could be further coalesced/condensed:

    IF(NOT EXISTS (SELECT *
                     FROM ranges
                    WHERE @low BETWEEN minimum AND maximum
                       OR @high BETWEEN minimum AND maximum))
    BEGIN
         INSERT INTO ranges
             (minumum, maximum)
           VALUES
             (@low, @high)
    END
    

    And even further:

    INSERT INTO ranges
       (minimum, maximum)
    SELECT T.minimum, T.maximum
      FROM (SELECT @low as minimum, @high as maximum) T
     WHERE NOT EXISTS (SELECT *
                         FROM ranges
                        WHERE @low BETWEEN minimum AND maximum
                           OR @high BETWEEN minimum AND maximum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a test table in MySQL and would like to insert 10
I need to insert data from table1 into table2. However, I would like to
using tsql, sqlserver 2005. I would like insert records from table table2 into an
I would like to insert a new node into my Tree. I develop with
I would like to insert the current Subversion revision number (as reported by svnversion
I would like to insert dates in an emacs buffer like I do in
I would like to insert notes on the fixes to be done in specific
I have a little problem where I would like to insert a svn diff
I would like to programmatically insert additional rows into a DataGrid (to act as
I would like to change the behaviour of the insert button on the standard

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.