473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

select all the duplicate records

Hi,

My table in the database may contain duplicate records, which means except
the primary key (auto_increment) field is unique, all or almost of all the
fields are with the same content. How can I select them to display and
delete them?
Thanks for any idea.

Atse
Jul 19 '05 #1
9 5966
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1

Cheers
Ken

"atse" <du******@yahoo.com> wrote in message
news:no********************@news04.bloor.is.net.ca ble.rogers.com...
: Hi,
:
: My table in the database may contain duplicate records, which means except
: the primary key (auto_increment) field is unique, all or almost of all the
: fields are with the same content. How can I select them to display and
: delete them?
: Thanks for any idea.
:
: Atse
:
:
Jul 19 '05 #2
Cool, thanks

"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1

Cheers
Ken

"atse" <du******@yahoo.com> wrote in message
news:no********************@news04.bloor.is.net.ca ble.rogers.com...
: Hi,
:
: My table in the database may contain duplicate records, which means except : the primary key (auto_increment) field is unique, all or almost of all the : fields are with the same content. How can I select them to display and
: delete them?
: Thanks for any idea.
:
: Atse
:
:

Jul 19 '05 #3
This lists all the duplicates only with one of each. If the record has more
than one duplicate, it can't show all of them but one only. Is there a way
to show all? Thanks again.

Atse
"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1

Cheers
Ken

"atse" <du******@yahoo.com> wrote in message
news:no********************@news04.bloor.is.net.ca ble.rogers.com...
: Hi,
:
: My table in the database may contain duplicate records, which means except : the primary key (auto_increment) field is unique, all or almost of all the : fields are with the same content. How can I select them to display and
: delete them?
: Thanks for any idea.
:
: Atse
:
:

Jul 19 '05 #4
Is this Access? I suggest using Ken's SQL to create a saved query called
qFindDups. Then create another query using this SQL:

Select t.* FROM myTable t INNER JOIN qFindDups q
ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3

HTH,
Bob Barrows
"atse" <du******@yahoo.com> wrote in message
news:CB**********************@news01.bloor.is.net. cable.rogers.com...
This lists all the duplicates only with one of each. If the record has more than one duplicate, it can't show all of them but one only. Is there a way
to show all? Thanks again.

Atse
"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1

Cheers
Ken

Jul 19 '05 #5
I am using MySQL. This doesn't work, which complains with myTable.qfinddups
doesn't exist.
"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Is this Access? I suggest using Ken's SQL to create a saved query called
qFindDups. Then create another query using this SQL:

Select t.* FROM myTable t INNER JOIN qFindDups q
ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3

HTH,
Bob Barrows
"atse" <du******@yahoo.com> wrote in message
news:CB**********************@news01.bloor.is.net. cable.rogers.com...
This lists all the duplicates only with one of each. If the record has

more
than one duplicate, it can't show all of them but one only. Is there a way to show all? Thanks again.

Atse
"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1

Cheers
Ken


Jul 19 '05 #6
Does MySQL allow subqueries in the FROM clause? If so, do this:

Select t.* FROM myTable t INNER JOIN
(
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1
) q
ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3

Please let us know upfront what database you are using so we don't waste our
time and yours giving you irrelevant solutions.

Bob Barrows
atse wrote:
I am using MySQL. This doesn't work, which complains with
myTable.qfinddups doesn't exist.
"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Is this Access? I suggest using Ken's SQL to create a saved query
called qFindDups. Then create another query using this SQL:

Select t.* FROM myTable t INNER JOIN qFindDups q
ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3

HTH,
Bob Barrows
"atse" <du******@yahoo.com> wrote in message
news:CB**********************@news01.bloor.is.net. cable.rogers.com...
This lists all the duplicates only with one of each. If the record
has more than one duplicate, it can't show all of them but one
only. Is there a way to show all? Thanks again.

Atse
"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1

Cheers
Ken


Jul 19 '05 #7
Sorry, I will complete my question next time.
I guess MySQL may not support substring? Because it complains with that:
Microsoft OLE DB Provider for ODBC Drivers error '80040e09'

[MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]You have an error in your
SQL syntax. Check the manual that corresponds to your MySQL server version
for the right syntax to use near 'SELECT f1, f3(

/dp_record.asp, line 37

Here is the line37 (please ignore the broken lines):
' file is myTable, and f1, f3 ... are the field names

dataSQL = "select t.* FROM file t INNER JOIN (SELECT f1, f3, f5 FROM file
GROUP BY f1, f3, f5 "
dataSQL = dataSQL & "HAVING Count(*) > 1) q ON t.f1=q.f1 AND t.f3=q.f3 AND
t.f5=q.f5"

"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:uk**************@TK2MSFTNGP11.phx.gbl...
Does MySQL allow subqueries in the FROM clause? If so, do this:

Select t.* FROM myTable t INNER JOIN
(
SELECT
Field1, Field2, Field3
FROM
myTable
GROUP BY
Field1, Field2, Field3
HAVING
Count(*) > 1
) q
ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3

Please let us know upfront what database you are using so we don't waste our time and yours giving you irrelevant solutions.

Bob Barrows
atse wrote:
I am using MySQL. This doesn't work, which complains with
myTable.qfinddups doesn't exist.
"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
Is this Access? I suggest using Ken's SQL to create a saved query
called qFindDups. Then create another query using this SQL:

Select t.* FROM myTable t INNER JOIN qFindDups q
ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3

HTH,
Bob Barrows
"atse" <du******@yahoo.com> wrote in message
news:CB**********************@news01.bloor.is.net. cable.rogers.com...
This lists all the duplicates only with one of each. If the record
has more than one duplicate, it can't show all of them but one
only. Is there a way to show all? Thanks again.

Atse
"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
> SELECT
> Field1, Field2, Field3
> FROM
> myTable
> GROUP BY
> Field1, Field2, Field3
> HAVING
> Count(*) > 1
>
> Cheers
> Ken


Jul 19 '05 #8
http://www.google.com.au/search?q=fi...rds+with+mySQL

Cheers
Ken

"atse" <du******@yahoo.com> wrote in message
news:JP*********************@news01.bloor.is.net.c able.rogers.com...
: Sorry, I will complete my question next time.
: I guess MySQL may not support substring? Because it complains with that:
:
:
: Microsoft OLE DB Provider for ODBC Drivers error '80040e09'
:
: [MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]You have an error in
your
: SQL syntax. Check the manual that corresponds to your MySQL server version
: for the right syntax to use near 'SELECT f1, f3(
:
: /dp_record.asp, line 37
:
:
:
: Here is the line37 (please ignore the broken lines):
: ' file is myTable, and f1, f3 ... are the field names
:
: dataSQL = "select t.* FROM file t INNER JOIN (SELECT f1, f3, f5 FROM file
: GROUP BY f1, f3, f5 "
: dataSQL = dataSQL & "HAVING Count(*) > 1) q ON t.f1=q.f1 AND t.f3=q.f3 AND
: t.f5=q.f5"
:
:
:
: "Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
: news:uk**************@TK2MSFTNGP11.phx.gbl...
: > Does MySQL allow subqueries in the FROM clause? If so, do this:
: >
: > Select t.* FROM myTable t INNER JOIN
: > (
: > SELECT
: > Field1, Field2, Field3
: > FROM
: > myTable
: > GROUP BY
: > Field1, Field2, Field3
: > HAVING
: > Count(*) > 1
: > ) q
: > ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3
: >
: > Please let us know upfront what database you are using so we don't waste
: our
: > time and yours giving you irrelevant solutions.
: >
: > Bob Barrows
: >
: >
: > atse wrote:
: > > I am using MySQL. This doesn't work, which complains with
: > > myTable.qfinddups doesn't exist.
: > >
: > >
: > > "Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
: > > news:Or**************@TK2MSFTNGP09.phx.gbl...
: > >> Is this Access? I suggest using Ken's SQL to create a saved query
: > >> called qFindDups. Then create another query using this SQL:
: > >>
: > >> Select t.* FROM myTable t INNER JOIN qFindDups q
: > >> ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3
: > >>
: > >> HTH,
: > >> Bob Barrows
: > >>
: > >>
: > >> "atse" <du******@yahoo.com> wrote in message
: > >> news:CB**********************@news01.bloor.is.net. cable.rogers.com...
: > >>> This lists all the duplicates only with one of each. If the record
: > >>> has more than one duplicate, it can't show all of them but one
: > >>> only. Is there a way to show all? Thanks again.
: > >>>
: > >>> Atse
: > >>>
: > >>>
: > >>> "Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
: > >>> news:eO**************@tk2msftngp13.phx.gbl...
: > >>>> SELECT
: > >>>> Field1, Field2, Field3
: > >>>> FROM
: > >>>> myTable
: > >>>> GROUP BY
: > >>>> Field1, Field2, Field3
: > >>>> HAVING
: > >>>> Count(*) > 1
: > >>>>
: > >>>> Cheers
: > >>>> Ken
: >
: >
: >
:
:
Jul 19 '05 #9
It seems there no effective way on that page. Did I miss one of them? Please
point out, Thanks

Atse

"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:ua**************@tk2msftngp13.phx.gbl...
http://www.google.com.au/search?q=fi...rds+with+mySQL

Cheers
Ken

"atse" <du******@yahoo.com> wrote in message
news:JP*********************@news01.bloor.is.net.c able.rogers.com...
: Sorry, I will complete my question next time.
: I guess MySQL may not support substring? Because it complains with that:
:
:
: Microsoft OLE DB Provider for ODBC Drivers error '80040e09'
:
: [MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]You have an error in
your
: SQL syntax. Check the manual that corresponds to your MySQL server version : for the right syntax to use near 'SELECT f1, f3(
:
: /dp_record.asp, line 37
:
:
:
: Here is the line37 (please ignore the broken lines):
: ' file is myTable, and f1, f3 ... are the field names
:
: dataSQL = "select t.* FROM file t INNER JOIN (SELECT f1, f3, f5 FROM file : GROUP BY f1, f3, f5 "
: dataSQL = dataSQL & "HAVING Count(*) > 1) q ON t.f1=q.f1 AND t.f3=q.f3 AND : t.f5=q.f5"
:
:
:
: "Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
: news:uk**************@TK2MSFTNGP11.phx.gbl...
: > Does MySQL allow subqueries in the FROM clause? If so, do this:
: >
: > Select t.* FROM myTable t INNER JOIN
: > (
: > SELECT
: > Field1, Field2, Field3
: > FROM
: > myTable
: > GROUP BY
: > Field1, Field2, Field3
: > HAVING
: > Count(*) > 1
: > ) q
: > ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3
: >
: > Please let us know upfront what database you are using so we don't waste : our
: > time and yours giving you irrelevant solutions.
: >
: > Bob Barrows
: >
: >
: > atse wrote:
: > > I am using MySQL. This doesn't work, which complains with
: > > myTable.qfinddups doesn't exist.
: > >
: > >
: > > "Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
: > > news:Or**************@TK2MSFTNGP09.phx.gbl...
: > >> Is this Access? I suggest using Ken's SQL to create a saved query
: > >> called qFindDups. Then create another query using this SQL:
: > >>
: > >> Select t.* FROM myTable t INNER JOIN qFindDups q
: > >> ON t.Field1=q.Field1 AND t.Field2=q.Field2 AND t.Field3=q.Field3
: > >>
: > >> HTH,
: > >> Bob Barrows
: > >>
: > >>
: > >> "atse" <du******@yahoo.com> wrote in message
: > >> news:CB**********************@news01.bloor.is.net. cable.rogers.com... : > >>> This lists all the duplicates only with one of each. If the record
: > >>> has more than one duplicate, it can't show all of them but one
: > >>> only. Is there a way to show all? Thanks again.
: > >>>
: > >>> Atse
: > >>>
: > >>>
: > >>> "Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
: > >>> news:eO**************@tk2msftngp13.phx.gbl...
: > >>>> SELECT
: > >>>> Field1, Field2, Field3
: > >>>> FROM
: > >>>> myTable
: > >>>> GROUP BY
: > >>>> Field1, Field2, Field3
: > >>>> HAVING
: > >>>> Count(*) > 1
: > >>>>
: > >>>> Cheers
: > >>>> Ken
: >
: >
: >
:
:

Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rich | last post by:
My table looks like this: char(150) HTTP_REF, char(250) HTTP_USER, char(150) REMOTE_ADDR, char(150) REMOTE_HOST, char(150) URL, smalldatetime TIME_STAMP There are no indexes on this table...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
2
by: Carroll | last post by:
I'm looking for a way in SQL to find duplicate records in a single table, that are the same based on 3 columns, regardless of what is in the other columns in the duplicate records. I would like to...
0
by: B.N.Prabhu | last post by:
Hi, I have a DataTable with several rows. Its having 20 Columns. when i click the Insert button then i have to check the Database Rows. Whether these new rows are already available in the...
0
by: pekx | last post by:
Hi, I create a script to pick up those records with duplication of IMIPROPSERVNO field, see below test1.sql, which is working.... test1.sql 1.SELECT IMIPROPSERVNO, COUNT(*) 2.FROM...
6
by: pooh80133 | last post by:
Hi! I am pasting my SQL code at the end of this message. I am trying to use SELECT DISTINCT in a query, but I am a beginner for using Access. Right now I have duplicate ID's (Indiv ID) in my...
7
by: Doug Bell | last post by:
Hi, I have a DataSet with a DataTable that has a number of duplicate rows (except for one column that has a unique value). Each row has OrderNo, OrderLineNo, etc and there are multiple rows...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
6
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.