?
Solved

SELECT SUBSTRING_INDEX question

Posted on 2007-10-09
3
Medium Priority
?
1,060 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:andyw27
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20039421
Try
Select SUBSTRING_INDEX(SUBSTRING_INDEX('www.mysql.com', '.', -2), '.', 1);
0
 

Author Comment

by:andyw27
ID: 20039425

Thats done it.  Can some explain how it works?

thanks.
0
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 2000 total points
ID: 20039437
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question