Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch Domain names from Urls in MySql [duplicate]

Tags:

mysql

Possible Duplicate:
How we can find domain name using MySQL and regular expression

My db table has a column called url which contains info like: http://xyz.com/cat/index/?page=2 http://www.google.com/webmaster.php http://yahoo.com/dsdsd/category.aspx etc.

I want to just fetch their domain names like: xyz.com google.com yahoo.com

How should I write the query in mysql to get the above result.

Please help.

like image 932
Future King Avatar asked Feb 20 '23 07:02

Future King


1 Answers

Someone in Digital Point gave me the answer

SELECT SUBSTRING_INDEX(REPLACE(REPLACE(url, "http://", ""), "www.", ""), '/', 1);
like image 177
Future King Avatar answered Feb 21 '23 23:02

Future King