Question: Need a generic sql query for joins that can run on mysql, postgres and other major DBs

I have a table named autumn4.ip , I have `three columns: id,start,end (all ints).`

How do I make a join so that I make use of BUT not by BETWEEN but by JOINS.

like pseudo:

```
select * FROM autumn.ip WHERE :number-constant >= start ORDER BY start DESC LIMIT 1; +

select * FROM autumn.ip WHERE :number-constant <= end ORDER BY start ASC LIMIT 1;

```

how to some one join the above two queries to get one row of data that would be equivalent to

```
SELECT * FROM autumn4.ip WHERE :number-constant BETWEEN START AND END LIMIT 1;

```

Just dont ask my why I am doing it :)
but I know you woudl so:

I am trying to accomplish is to use 2 indexes, start and end. if i use BETWEEN and/or a composite index of start,end. Only start index is used and not the end. now please dont tell me that I am wrong. I just want it that way. I have done alot of research on this

if i do create single indexes for both start and end, only one is used. give me a query in which both are used

Answer: 
I would typically use the pattern

```
foo = data.get("a",{}).get("b",{}).get("c",False)
if foo:
...

```

This requires that the nesting is always the same depth and that data["a"]["b"]["c"] is not "falsy".
If you need to do this multi-level lookup very often, this helper method can be useful:

```py
def multi_get(dict_obj, *attrs, default=None):
    result = dict_obj
    for attr in attrs:
        if attr not in result:
            return default
        result = result[attr]
    return result

```

To use it, just call it like:

```py
x = multi_get(data, 'a', 'b', 'c', default=False)

```