What's the optimal way to query data using another table column as a between filter
What's the optimal query to having such a result? 


Simple. 

Create proper indices (order(ip) and ip(ip_from,ip_to)).

Complex.

Create a field of LINESTRING type from ip_from to ip_to. Create spatial index (RTree) by it. Use MBRContains for filtering.



From the other side - the ranges (ip_from,ip_to) must be NON-overlapped.

If it is true, then you'll obtain the result with simple

select order.uid, 
       order.order_id, 
       order.ip, 
       ( SELECT ip.country_code
         FROM ip
         WHERE ip.ip_from &lt;= order.ip
         ORDER BY ip.ip_from DESC
         LIMIT 1 ) country_code
from order


Indices ip(ip_from) and order(ip) (or even covering index ip(ip_from, country_code)) is enough for this query.