Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to sort by IP addresses in SQL

I connect to my SpiceWorks database via PHP using the SQLITE3 PDO. I am trying to display a list of devices in order by IP address. Here is my current query:

SELECT name, ip_address FROM `devices` ORDER BY ip_address

The problem with this is that it organizes them weird like this:

enter image description here

Is there any easy way to fix this problem?

It is not possible for me to edit the database because it would through SpiceWorks off. I need a way to do this in SQL.

like image 517
AJ Birone Avatar asked Apr 15 '14 19:04

AJ Birone


1 Answers

Have you tried INET_ATON function? This is probably a late answer, but maybe it'll help others.

SELECT name, ip_address
FROM devices
ORDER BY
INET_ATON(ip_address)
like image 171
Nekkyo Avatar answered Sep 29 '22 01:09

Nekkyo