# Duplicate guest accounts

**URL:** https://forum.shopware.com/t/duplicate-guest-accounts/96565
**Category:** General Questions (EN)
**Created:** [6. Oktober 2022 um 12:59 UTC](https://forum.shopware.com/t/duplicate-guest-accounts/96565 "2022-10-06T12:59:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![joris.van.os](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@joris.van.os](https://forum.shopware.com/u/joris.van.os)
#### Post date: [6. Oktober 2022 um 12:59 UTC](https://forum.shopware.com/t/duplicate-guest-accounts/96565/1 "2022-10-06T12:59:31Z")

</div>

Hi,

Does anyone know how to prevent (or more likely merge) duplicate quest accounts based on the same email address, after a customer places an order without registering and does this over time?

We don’t want to disable the option for the customer to place an order without registration. But multiple guest account of the same customer would pollute our database.

Hopefully someone else encountered the same problem and found a solution. Many thnx!

---

<div class="post-metadata">

### Author: ![tim2](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/tim2/32/19833_2.png) [@tim2](https://forum.shopware.com/u/tim2)
#### Post date: [1. November 2023 um 13:19 UTC](https://forum.shopware.com/t/duplicate-guest-accounts/96565/2 "2023-11-01T13:19:29Z")

</div>

Hi Joris,

Did you ever found a solution for this. We are looking at the same issue here. Some guests have 20+ ‚customer‘ accounts.

BTW there is an option in Settings → Log-in & signup called:

_Expiry time of guest customer accounts_

Standard is 86400 second which is 24 hours.

But that does not prevent the auto-increment of the customer numbers though.

You can find more information here:

> <https://github.com/shopware/shopware/blob/trunk/changelog/release-6-4-7-0/2021-11-04-added-delete-unused-guest-customer-command-and-task.md>

However I’ve set it to 10 seconds and ran the command, but it claims that there are no unused guest accounts, so nothing is deleted. Probably because they don’t consider guest unused if they have placed an order. The code has to be altered to delete all guest accounts I think.

---

<div class="post-metadata">

### Author: ![tim2](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/tim2/32/19833_2.png) [@tim2](https://forum.shopware.com/u/tim2)
#### Post date: [8. Dezember 2023 um 11:49 UTC](https://forum.shopware.com/t/duplicate-guest-accounts/96565/3 "2023-12-08T11:49:26Z")

</div>

This query can be tested in your environment. It works for customers that are bound to a sales channel:

```auto
UPDATE order_customer oc
INNER JOIN (
    SELECT c1.id AS customer_id, c1.email, c1.bound_sales_channel_id, c1.customer_number, oc.order_id, (
        SELECT MIN(c2.id)
        FROM customer c2
        WHERE c2.email = c1.email
    ) AS oldest_customer_id
    FROM customer c1
    INNER JOIN order_customer oc ON c1.id = oc.customer_id
    WHERE c1.guest = 1
    AND (
        SELECT COUNT(*)
        FROM customer c2
        WHERE c2.email = c1.email
        AND c2.bound_sales_channel_id = c1.bound_sales_channel_id
        AND c2.customer_number < c1.customer_number
    ) > 0
) AS customer_data ON oc.customer_id = customer_data.customer_id
SET oc.customer_id = customer_data.oldest_customer_id;

```

It moves guest orders to the oldest guest account available. Achter this the other guests accounts are empty and can be deleted with the ‚Unused Guests‘ CLI.
