0

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

1 Answer 1

1

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
--------------
Sign up to request clarification or add additional context in comments.

1 Comment

i was looking for an php side solution for OP but i'm still faberglasted by how much SQL can do for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.