Or, you could use distinct and substring_index instead of my last convoluted answer :)

> -----Original Message-----
> From: Kip Turk [mailto:kipt@;wcc.net]
> Sent: Monday, November 04, 2002 4:17 PM
> To: Alexander Newald
> Cc: mySQL Mailing Liste
> Subject: Re: Difficult query
> 
> 
> On Mon, 4 Nov 2002, Alexander Newald wrote:
> 
> > Hello,
> > 
> > I have a table with only ips in it. I want to get all 
> networks the ips
> > belong to:
> > 
> > Example:
> > 
> > 123.123.123.1
> > 123.123.132.2
> > 123.123.123.3
> > 1.1.1.4
> > 1.1.1.5
> > 1.1.1.6
> > 12.12.12.1
> > 12.12.12.2
> > 12.12.12.10
> > 
> > The result should be:
> > 
> > 123.123.123.0
> > 1.1.1.0
> > 12.12.12.0
> > 
> > Instead of converting on matching row (for example 123.123.123.2) to
> > 123.123.123.0 it can be left as 123.123.123.2 or even can 
> be truncated to
> > 123.123.123
> > 
> > The table is stored on a 3.23.43 mySQL Server. The table 
> type is varchar(15)
> > but this can be changed.
> 
> Possibly not the most optimized solution, but it functions as 
> requested.
> 
> select distinct(concat(substring_index(field, '.', 3), '.0')) 
> as network from table order by network;
> 
> field and table should be replaced with your actual names of course.
> 
 

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to