Andy,

Just:

select substring_index(surname,' ',-1) as r from advisers order by r;

works.

Andy

> -----Original Message-----
> From: andy thomas [mailto:[EMAIL PROTECTED]
> Sent: 08 June 2004 15:57
> To: Andy Eastham
> Cc: Mysql List
> Subject: RE: RE - Order By Problem
> 
> On Tue, 8 Jun 2004, Andy Eastham wrote:
> 
> > Look at using the Reverse() function, then take the substring up to the
> > first space, then reverse the result.
> 
> Well, 'select substring_index(surname,' ',-1) from advisers' does the
> trick as far as extracting the wanted parts of surnames at the end of
> the surname filed but I'm not sure how to use this as an argument to
> ORDER BY? Shouldn't something like:
> 
> select substring_index(surname,' ',-1) as r from advisers, select * from
> advisers order by r
> 
> work?
> 
> Thanks for your help,
> 
> Andy
> 
> > > -----Original Message-----
> > > From: Paul McNeil [mailto:[EMAIL PROTECTED]
> > > Sent: 08 June 2004 14:04
> > > To: [EMAIL PROTECTED]
> > > Subject: RE - Order By Problem
> > >
> > > I have never done anything like this but after looking at the spec's I
> > > have
> > > a possible direction for you....
> > >
> > > In String functions there is
> > >
> > > LOCATE(substr,str,pos)
> > > The first syntax returns the position of the first occurrence of
> substring
> > > substr in string str. The second syntax returns the position of the
> first
> > > occurrence of substring substr in string str, starting at position
> pos.
> > > Returns 0 if substr is not in str.
> > >
> > > I think that if you create a function that uses this to strip the
> string
> > > to
> > > the left of the last found space and that returns the string to the
> right
> > > you could call this in your query and use it in the order by
> statement.
> > >
> > >
> > >
> > > --
> > > MySQL General Mailing List
> > > For list archives: http://lists.mysql.com/mysql
> > > To unsubscribe:
> http://lists.mysql.com/[EMAIL PROTECTED]
> >
> >
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> http://lists.mysql.com/[EMAIL PROTECTED]
> >
> 
> 
> 
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to