For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > November 2005 > Extracting part of a string









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Extracting part of a string
laredotornado@zipmail.com

2005-11-23, 6:57 pm

Hello,

Using MySQL 4, how do I write a SELECT statement that returns the
portion of the string after the last comma in the string? That is, if
I have a field with a value

"a,b,c,d,e"

and

"a,b,c,eee"

I would like to write an SQL statement that returns "e" in the first
case and "eee" in the second case.

Thanks for your help, - Dave

ZeldorBlat

2005-11-23, 6:57 pm

substring_index(someCol, ',', -1);

laredotornado@zipmail.com

2005-11-23, 6:57 pm

Thanks so much. That is very slick.

What if I wanted to get the first parts of the strings? That is,
"a,b,c,d" and "a,b,c"?

- Dave

ZeldorBlat

2005-11-24, 6:57 pm

>What if I wanted to get the first parts of the strings? That is,
>"a,b,c,d" and "a,b,c"?


Don't know, but you might be able to find the answer here:

<http://dev.mysql.com/doc/refman/4.1...-functions.html>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com