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))
);
If I’m not understanding you incorrectly…
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)
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,
might help you to see it. Note that you can not group the result by
f2andf3because you might havebut you might also have