• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can i run this query in code igniter

#1
[eluser]rajneeshgobin[/eluser]
how can i write this kind of query in code igniter

basically it 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

#2
[eluser]CroNiX[/eluser]
Code:
$this->db
  ->select('roleID, permID')
  ->select('count(*) as NumDuplicates', FALSE)
  ->group_by(array('roleID', 'permID'))
  ->having('NumDuplicates > 1')
  ->get('role_perms')
  ->result();
Code:
//Produces
SELECT roleID, permID, count(*) as NumDuplicates
FROM (role_perms)
GROUP BY roleID, permID
HAVING NumDuplicates > 1

Haven't tried it as I don't have your tables, but probably something like that


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.