Welcome Guest, Not a member yet? Register   Sign In
how can i write this query
#1

i need a query which will delete duplicate entries from my database.

the query below tells me which rows of my table has duplicates based on the selected parameters in this case role id and perm id

select roleID, permID, count(*) as NumDuplicates
from `role_perms`
group by roleID, permID
having NumDuplicates > 1

from the previous forum a member converted this to

$this->db
->select('roleID, permID')
->select('count(*) as NumDuplicates', FALSE)
->group_by(array('roleID', 'permID'))
->having('NumDuplicates > 1')
->get('role_perms')
->result();

i wish to extend this so that it delete the duplicate values and keep only one in the table. if there is for example 1 original entry and 2 more duplicates, then it deletes teh 2 duplicate leaving the 1 entry.
Reply


Messages In This Thread
how can i write this query - by rajneeshgobin - 11-04-2014, 10:42 PM
RE: how can i write this query - by Jeroen - 11-05-2014, 05:17 AM
RE: how can i write this query - by Rufnex - 11-05-2014, 07:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB