Finding Domains Name From Email Addresses in MySQL
The other day I wanted to know how many unique domain names existed in the emails addresses of one of our databases. I started looking for an easily way to find them and how common each domain was. The query below will give you those details.
Query
There’s a lot going on here but the important part is the right(email, length(email) - locate('@', email))
calculation. Let’s break it down a little:
- The
right(email, x)
function is taking the last x characters from the email address which should be the domain name. - In order to find the x for the
right()
function where usinglength(email) - locate('@', email)
which is taking the total length of the email address and removing the number of characters up to the “@” sign.
Output
I’ve removed the count(*)
value because this was run on production data but it’s interesting to see the top providers:
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
RSS
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows