SELECT SUBSTRING_INDEX question

Hello,

I'm trying to get this to function to work.  I have this code:

SELECT SUBSTRING_INDEX('www.google.com', '.', 1)

And I want it to return 'google'

Any suggestions?

Thanks.
andyw27Asked:
Who is Participating?
 
Ashish PatelCommented:
This may help you understand.

Syntax: SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
        -> 'www.mysql'
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
        -> 'mysql.com'

Also referer to the link below for all function syntaxs.
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index
0
 
Ashish PatelCommented:
Try
Select SUBSTRING_INDEX(SUBSTRING_INDEX('www.mysql.com', '.', -2), '.', 1);
0
 
andyw27Author Commented:

Thats done it.  Can some explain how it works?

thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.