Dear all,
I try to retrieve duplicate data from database but it take a lot of time to display and very slow.Even using index also same .Here is my sql statement :
$sqlselect2 = "SELECT DISTINCT p1.resume_id, p1.user_id, p1.email, p1.name, p1.gender, p1.house_tel, p1.office_tel, p1.hand_tel, p1.new_ic, p1.old_ic, p1.address1, p1.address2, p1.city, p1.dob FROM resume_personal p1 ,resume_personal p2 where p1.$searchString=p2.$searchString And p1.resume_id!=p2.resume_id Order by p1.$sort $order ";
$result2 = mysql_query($sqlselect2,$conn) or die(mysql_error());
Anyones got the better solution to retrieve duplicate data or to improve the speed?Thanks.
erickwidya
June 23rd, 2005, 01:09 AM
use GROUP BY instead DISTINCT
"SELECT p1.resume_id, p1.user_id, p1.email, p1.name, p1.gender, p1.house_tel, p1.office_tel, p1.hand_tel, p1.new_ic, p1.old_ic, p1.address1, p1.address2, p1.city, p1.dob FROM resume_personal p1
GROUP BY p1.resume_ID, p1.user_id, p1.email, p1.name, p1.gender, p1.house_tel, p1.office_tel, p1.hand_tel, p1.new_ic, p1.old_ic, p1.address1, p1.address2, p1.city, p1.dob
Order by p1.$sort $order ";
btw why u use this
...FROM resume_personal p1 ,resume_personal p2 where p1.$searchString=p2.$searchString And p1.resume_id!=p2.resume_id
Order by p1.$sort $order "to me : the JOIN not necessary
suppose in tblEmployees, the firstname, lastname and phoneNumber should be distinct. if they arent then you have duplicates you need to remove so you do:
select *
from
tblEmployees t,
(select firstName, lastName, phoneNum
from tblEmployees
group by firstName, lastName, phoneNum
having count(*)>1) dupFinder
where
t.firstName = dupFinder.firstname and
t.lastname = dupfinder.lastname and
t.phonenum = dupfinder.phonenum
here we have a small sql that we can think of as a temporary table:
(select firstName, lastName, phoneNum
from tblEmployees
group by firstName, lastName, phoneNum
having count(*)>1)
if finds the first,last and phone that appear more than once in the table
then the outer query pulls all the columns from tblemployees, of these duplicates
remove duplicates once; dont forever use distinct or group to remove them at query time
erickwidya
June 23rd, 2005, 10:58 PM
haw_fongi think u have an issue in designing the table
if u can get the "Nomalize form" for it, i think u'll get performance speed up
decide what counts as a duplicate to you..cjard's got a point here
and tell us what this table is for..the purpose of it
regards
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.