max | last INET in table

Started by Roderick A. Andersonover 23 years ago3 messagesgeneral
Jump to latest
#1Roderick A. Anderson
raanders@acm.org

Well this will seem strange but I'm trying to figure out a way to select
the last INET value in a table. I found that max() isn't defined for
inet and a max(text()) gives - obviously - an alphabetical max which is
incorrect.

Is there a function I've missed or a SQL trick to get the last IP address
out of a table?

TIA,
Rod
--
"Open Source Software - Sometimes you get more than you paid for..."

#2Peter Gibbs
peter@emkel.co.za
In reply to: Roderick A. Anderson (#1)
Re: max | last INET in table

Roderick A. Anderson wrote:

Well this will seem strange but I'm trying to figure out a way to select
the last INET value in a table. I found that max() isn't defined for
inet and a max(text()) gives - obviously - an alphabetical max which is
incorrect.

Is there a function I've missed or a SQL trick to get the last IP address
out of a table?

select <inet field> from <table> order by <inet field> desc limit 1;

This will also use an index on <inet field> if there is one, in which
case it would have been faster even if max() worked.

--
Peter Gibbs
EmKel Systems

#3Roderick A. Anderson
raanders@acm.org
In reply to: Peter Gibbs (#2)
Re: max | last INET in table

On Thu, 12 Sep 2002, Peter Gibbs wrote:

select <inet field> from <table> order by <inet field> desc limit 1;

Geez I knew there was away. In fact I think I've got an old message with
a similar situation that uses this.

This will also use an index on <inet field> if there is one, in which
case it would have been faster even if max() worked.

Good point.

Again thanks,
Rod
--
"Open Source Software - Sometimes you get more than you paid for..."