Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8320463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:39:38+00:00 2026-06-08T22:39:38+00:00

I have a column contains urls. Some (but not all) urls share the same

  • 0

I have a column contains urls. Some (but not all) urls share the same domain. Ex: aaa.yahoo.com, bbb.yahoo.com, ccc.yahoo.com. These urls are stored in a unique field. Also, the same table has an auto-increment primary key.

What I need to do and need help on it is: Query all the urls that share the same domain name. Note that, there is no exact domain name that I can put in the query, a lot of the shared domain names available in the database and I want to query them all.

EDIT:
This is the command I’ve tried but totally not sure as I don’t have that much experience in SQL:

SELECT domainname FROM DB.TABLE
WHERE SUBSTRING(domainname, LOCATE('.', domainname))
IN(
    SELECT   domainname
    FROM     DB.TABLE
    GROUP BY SUBSTRING(domainname, LOCATE('.', doaminname)) 
);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:39:40+00:00Added an answer on June 8, 2026 at 10:39 pm

    If I’m not understanding you incorrectly…

    SELECT
        COUNT(`domainname`) AS 'occ'
        ,SUBSTRING(`domainname`,LOCATE('.',`domainname`)+1) AS 'domain'
    FROM `the_table`
    GROUP BY SUBSTRING(`domainname`,LOCATE('.',`domainname`)+1)
    HAVING `occ`>1
    ORDER BY `occ` DESC,`domain` ASC
    

    The HAVING... line will filter out the domains that have only 1 occurence in the table.


    EDIT:

    Speaking on behalf of your comments… Because you can not know which is domain in the following examples (unless you test the values against a huge list of country codes, domain extensions etc)

    • domain.co.uk
    • subdomain.domain.co

    you can not programmatically detect those. If you’re planning to rely on extension or the country extension, that won’t work either. What you can do is get a smart sorting and pick the ones by your eyes, that is unless you go about the above mentioned solution.

    So, for example,

    SELECT
        `id`
        ,`d` AS 'domain'
        ,IF(CHAR_LENGTH(`d`)-CHAR_LENGTH(REPLACE(`d`,'.',''))=2,
            SUBSTRING_INDEX(`d`,'.',1),'') AS 'f1'
        ,SUBSTRING_INDEX(SUBSTRING_INDEX(`d`,'.',-2),'.',1) AS 'f2'
        ,SUBSTRING_INDEX(`d`,'.',-1) AS 'f3'
    FROM (
        SELECT
            `id`
            ,IF(CHAR_LENGTH(`domainname`)-CHAR_LENGTH(REPLACE(`domainname`,'.',''))>2,
                SUBSTRING_INDEX(`domainname`,'.',-3),`domainname`) AS 'd'
        FROM `the_table`
        GROUP BY `d`
    ) t
    ORDER BY `f3`,`f2`,`f1`
    

    might help you to see it. Note that you can not group the result by f2 and f3 because you might have

    • example1.yahoo.com
    • example2.yahoo.com

    but you might also have

    • yahoo.com.br
    • google.com.br
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string column which contains some numeric fields, but a lot are
I have a table which contains URLs, some of which are longer than 255
I have a column which contains null values in some of the rows. I
I have a column that contains links. The problem is that the titles of
For each row I have a column which contains numbers like this 1,4,6,3,16,13 .
In my SQL database I have a column that contains a fiscal year value.
I have a database column that contains the contents of a file. I'm converting
I have a table where last column contains action buttons which opens another section
I have a datagridview in which one column contains a custom class, which I
I have a table in Oracle where one of the column contains UserIds which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.