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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:54:15+00:00 2026-05-28T16:54:15+00:00

I have a table with 2 columns, cola and colb, which represent a range

  • 0

I have a table with 2 columns, cola and colb, which represent a range of numbers.

Example problem:

cola - colb
1    - 10
11   - 22
33   - 66
67   - 67
  • if the input is 7-8, I would like a query that would extract the range 1-10.
  • if the input is 67 – 80, I would like a query that would extract 67 – 67

Example query:

SELECT * 
  FROM example 
 WHERE vala >= cola 
   AND valb <= colb

The first criterion works great with the above query however it falls down when cola = colb ie.. 67 – 67.


The above is a simple example of my issue.. The problem is actually a range of Ips.
Cola – Colb2 = Ip range. I have included in case something is missing in the above example.

   SELECT *
     FROM `static_allocation`

    WHERE INET_ATON('$network_addr')   >= INET_ATON(network_addr)
      AND INET_ATON('$broadcast_addr') <= INET_ATON(broadcast_addr)

    LIMIT 1

Edit:

OK, it appears i am slightly wrong ..

Table data

10.0.0.0 - 10.0.0.15 
10.0.0.16 - 10.0.0.16

however when i try and select 10.0.0.16 - 10.0.0.20, it doesn’t find the record..

  • 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-28T16:54:16+00:00Added an answer on May 28, 2026 at 4:54 pm

    If you’re looking for the first range that contains at least a part of the block, try a condition like:

    vala <= colb and cola <= valb
    

    This says the search range [vala,valb] must partially overlap with the target range [cola,colb].

    In SQL:

    select  *
    from    example
    where   vala <= colb and cola <= valb
    order by
            cola -- Lowest network range
    limit   1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with around 15 columns. What I would like to be
I have two varchar columns ( ColA, ColB ) in a single table (
I have table which contains columns like SiteID (identity_Col) SiteName POrderID Location Address Cluster
Basically, if I have a table with composite indices (colA, colB, colC) and (colB,
I have my table columns set like this: likes(id, like_message, timestamp) id is the
I have a table with values ID BarID FName LName ColA ColB ColC 1
I have a table with the following column & value: ColA = 8765 ColB
Group, I have table columns ProductID, latitude,longitude,timestampGMT and looking for a query to count
I have such query. It returns ColA and ColB from TableA and UserName from
If I have a table with columns like ID1 ID2 VAL1 VAL2 Where ID1,ID2

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.