[Guide] Database Cleanup

09/30/2012 13:54 no_1#1
Tired of having more account then characters? of people that created mutiple accounts but just use 1 or when people deleted there characters.

Here is a way to get rid of these

Code:
SELECT DISTINCT
account. *
FROM account
LEFT JOIN cq_user ON account.id = cq_user.account_id
WHERE
account.id = ( cq_user.account_id)
This query will give you a new table with account that have a character bounded to it.
Once you got this
Export the new table into a sql file
Empty you old account table
Import this new sql file into your account table

Your done

Similar code to clean up items and eudemons for delete character

Code:
SELECT DISTINCT
cq_item.*
FROM cq_item
LEFT JOIN cq_user ON cq_item.player_id = cq_user.id
WHERE
cq_item.player_id = ( cq_user.id)

SELECT DISTINCT
cq_eudemon. *
FROM cq_eudemon
LEFT JOIN cq_user ON cq_eudemon.player_id = cq_user.id
WHERE
cq_eudemon.player_id = ( cq_user.id)
Regards SweetCandy[PM]
09/30/2012 17:29 Gekru#2
Why would you want to select the entries then export when you can just delete them from the database all in one step. The following is an example for the account table, it will delete all the rows from account where a character doesn't exist.

Code:
DELETE account FROM account 
LEFT JOIN cq_user ON account.id = cq_user.account_id 
WHERE cq_user.account_id IS NULL
10/01/2012 13:44 funhacker#3
also... doing a select distinct is used for selecting only 1 of many copies
an example would be

Code:
select distinct ownerid from cq_goods;
This will return all the owner ids within cq_goods without showing duplicates, this can be handy if you want to know what npc's sell items
however doing a select distinct * in a table with a primary key is pointless as it will never have duplicate entries...
12/08/2015 03:37 haizamlee#4
Quote:
Originally Posted by Gekru View Post
Why would you want to select the entries then export when you can just delete them from the database all in one step. The following is an example for the account table, it will delete all the rows from account where a character doesn't exist.

Code:
DELETE account FROM account 
LEFT JOIN cq_user ON account.id = cq_user.account_id 
WHERE cq_user.account_id IS NULL
how bout if we want to delete items n eudemons that players doesnt exist.