WHMCS guide

How to find duplicate clients in WHMCS.

One person on two accounts means split invoices, credit sitting on the account nobody opens and a support history in two places. Comparing e-mail addresses as typed misses much of it: on one of our own installs that comparison finds nothing, while ignoring Gmail dots and +tags finds over 100 groups to review.

DMS.S2 — Before you start

Before you run anything.

Read only

Every query below is a SELECT. It changes nothing. Run it in phpMyAdmin or the mysql client, on a copy of the database if you have one.

A match is a lead, not a verdict

A family or an office can share a phone or a mailbox. Open both accounts before you decide they are one client.

Merging cannot be undone

Take a database backup first, and check services, open invoices and credit on both accounts.

DMS.S3 — The queries

Four ways to find them.

Same e-mail, as typed

Ignores capital letters and stray spaces.

SELECT LOWER(TRIM(email)) AS mailbox, GROUP_CONCAT(id ORDER BY id) AS client_ids
FROM tblclients
GROUP BY mailbox
HAVING COUNT(*) > 1;

Same Gmail inbox, written differently

Gmail delivers j.doe+host@gmail.com and jdoe@gmail.com to the same person.

SELECT REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(LOWER(TRIM(email)), '@', 1), '+', 1), '.', '') AS inbox,
       GROUP_CONCAT(id ORDER BY id) AS client_ids
FROM tblclients
WHERE LOWER(TRIM(email)) LIKE '%@gmail.com'
GROUP BY inbox
HAVING COUNT(*) > 1;

Same tax ID

Ignores dots, dashes and slashes. REGEXP_REPLACE needs MySQL 8 or MariaDB 10.

SELECT REGEXP_REPLACE(UPPER(tax_id), '[^A-Z0-9]', '') AS tax,
       GROUP_CONCAT(id ORDER BY id) AS client_ids
FROM tblclients
GROUP BY tax
HAVING tax <> '' AND COUNT(*) > 1;

Same phone and last name

Compares the last 10 digits, so a country code does not hide the match.

SELECT RIGHT(REGEXP_REPLACE(phonenumber, '[^0-9]', ''), 10) AS phone, LOWER(TRIM(lastname)) AS surname,
       GROUP_CONCAT(id ORDER BY id) AS client_ids
FROM tblclients
GROUP BY phone, surname
HAVING CHAR_LENGTH(phone) >= 8 AND COUNT(*) > 1;

DMS.S4 — The addon

Or get the list inside the WHMCS admin.

Brasa Duplicate Clients runs these comparisons and more, shows what each account holds and which one to keep, and e-mails admins when a new group appears. It never merges anything.

Brasa Duplicate Clients screen in the WHMCS admin, with sample data

Brasa Duplicate Clients

$39 per year

Finds the accounts that look like the same person or company, so you can merge the right ones.

  • Same mailbox, ignoring capital letters, +tags and Gmail dots
  • Same tax ID, same name and phone, same name and postcode
  • Each group shows services, open invoices and credit, and which account to merge into
  • One mailbox behind unrelated last names is listed last, as possible fake signups
First run in 16 seconds, on sample data: the summary, then each group of accounts with the one to keep. Brasa Duplicate Clients on the WHMCS Marketplace
Buy for $39

DMS.S5 — Questions

Merging duplicate accounts.

How do I merge two client accounts in WHMCS?

Open the account you want to remove, click Merge Clients Accounts on its Summary tab and enter the ID of the account to keep. The merge cannot be undone.

Which account should I keep?

Usually the one with the active services and the payment history. Check open invoices and credit on both before merging.

DMS.S6 — Start a project

Found a case these queries miss?

Tell us how the two accounts differ. If other hosts would hit it, it may become a check.