Dynadot โ€” .com Transfer

[PHP] MySQL Ranges

NamecheapNamecheap
Watch

beaver6813

Established Member
Impact
16
Hi Guys,

I've got a database full of numbers that should be contiguous, but some aren't ie:
Code:
23
24
25
26
27
29
30
31
32

I need to get the ranges of this, ie.
Code:
24-27 29 30-32
I've had a look about but I can't find any implementations efficient enough for use on large amounts of data, any ideas what MySQL queries could achieve this?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
It would be tough to achieve the intended result just with a query. You'll need coding. You would need to sort the numbers, then when there is a gap you handle it accordingly.
 
0
•••
0
•••
that's just genius, I love to see tricks like this
 
0
•••
That's a great solution.

Just curious though, would creating a temporary table for a very large query have a performance hit?
 
0
•••
That's a great solution.

Just curious though, would creating a temporary table for a very large query have a performance hit?

Just put that to the test... unfortunately yes, significantly even on only 6000 records it took about 5 seconds to process. So I'm trying to find another pure MySQL solution, any ideas? :D

EDIT: Just for future reference I found the best solution was in the end to retrieve all the numbers from the database and then loop over them all creating ranges. Its a lot faster than the queries, most probably because its all in memory after it retrieves the results from the database.
 
Last edited:
0
•••
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back