How do I get the domain name from a full URL in MySQL?

I too had that same question friend. It is actually quite simple thankfully!

This little snippet should do the trick for you:

SELECT count(visit_id) as total_visits,
SUBSTRING_INDEX(TRIM(leading "http://" from TRIM(url_column_from_table)),'/',1) as url_visited
FROM url_visits
GROUP BY 1;

Tags:

Thursday, August 11th, 2011 MySQL

Leave a Reply

You must be logged in to post a comment.

[ad code=1 align=center]