If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Display duplicate entries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-06, 06:57
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
Display duplicate entries

I was trying to make the column col1 UNIQUE but phpMyAdmin gave #1062 - Duplicate entry 'text1' for key 2
Code:
ALTER TABLE `tbl1` ADD UNIQUE (`col1`) ;
There seems to be many duplicate entries which wont make my ALTER TABLE work - I want to view all entries that have a duplicated col1 - how do I for this query ?

Thanks
Reply With Quote
  #2 (permalink)  
Old 03-02-06, 07:23
doubtsdb doubtsdb is offline
Registered User
 
Join Date: May 2005
Posts: 13
Hi,
You Can Remove Your duplicate enteries by the following Sql Query

Create Table TableName1 as Select distinct(filedname) from TableName

For Example

Create Table samplenew as Select distinct(sl_no) from Sample;

Then you can use the samplenew for your alter statement (or) you can rename the samplenew to sample by deleting the sample table.

I hope i would be helpfull to you

Regards

Balaji
Reply With Quote
  #3 (permalink)  
Old 03-02-06, 07:57
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
I wanted to display the duplicate values - anyway I got a workaround using HAVING. But I wanted the id also to be displayed alongside each duplicate entry.
The following query would return 50 rows - say there are 2 duplicates for each row (COUNT(`col1`) being 2 for each row) - but I was hopin for a solution to return 100 rows, id, col1.
Code:
SELECT `col1`, COUNT(`col1`)
FROM `tbl1`
GROUP BY `col1`
HAVING COUNT(`col1`) > 1
Thanks anyway,
Reply With Quote
  #4 (permalink)  
Old 03-02-06, 19:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
display the rows that have dupe col1 values:
Code:
select id, col1
  from tbl1
 where col1
    in (
       SELECT col1
         FROM tbl1
       GROUP 
           BY col1
       HAVING COUNT(*) > 1
       )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-03-06, 00:07
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
Thanks very much - this did solve my problem - this query on my laptop took 8 min to execute though ! Is there any way to optimize it for speed ? The table has 6000 records. Im sure my linux server host would be faster, but the number of records will grow over time.
Reply With Quote
  #6 (permalink)  
Old 03-03-06, 04:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
create an index on col1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 03-03-06, 09:31
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
My initial reason for all this was because I wanted to make col1 UNIQUE. Now that I got all duplicates and replaced them with different values, I did
ALTER TABLE `tbl1` ADD UNIQUE (`col1`) ;
But this is after I changed duplicate entries, before that on what basis can I create an index ?
Reply With Quote
  #8 (permalink)  
Old 03-03-06, 10:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
ALTER TABLE tbl1 ADD INDEX (col1) ;
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 03-03-06, 11:29
anjanesh anjanesh is offline
Registered User
 
Join Date: Feb 2005
Location: Mumbai, India
Posts: 161
Im assuming this statement given above was to be done before my correcting duplicates and making col1 unique.
But creating an index with no size would make no difference would it ?
Reply With Quote
  #10 (permalink)  
Old 03-03-06, 12:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
what does "with no size" mean?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On