iKev61
iKev61

Reputation: 194

SELECT specific string pattern from mysql table

this is what I know

SELECT domain FROM domain_table GROUP BY domain

Here is a possible result

www.domain.com, domain.com, sub.domain.com, domain.co/a-page

Is it possible to apply regex (or a hack) to the above select statement so that i will get domain.co instead of domain.co/a-page

Upvotes: 0

Views: 39

Answers (1)

peterm
peterm

Reputation: 92785

If I understand your question correctly you can try

SELECT SUBSTRING_INDEX(domain, '/', 1) domain
  FROM domain_table
 GROUP BY SUBSTRING_INDEX(domain, '/', 1)

Here is a dbfiddle demo

Output:

domain
--------------
domain.co
domain.com
sub.domain.com
www.domain.com
--------------

Upvotes: 1

Related Questions