Duplicate Records From a Table

G

Guest

I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
G

Guest

Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1
 
G

Guest

Thanks for the help but the query comes back blank - without any results.

Ofer said:
Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1



R Layedra said:
I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
G

Guest

Can post your SQL

R Layedra said:
Thanks for the help but the query comes back blank - without any results.

Ofer said:
Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1



R Layedra said:
I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
G

Guest

Hi Ofer,

My SQL skills are not quite refined yet!
This is what I exactly typed:

In (SELECT Left([APP_KEY],9) AS Expr1
FROM [Nancys Daily report (rev A)] GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1)

What is wrong with it?

Ofer said:
Can post your SQL

R Layedra said:
Thanks for the help but the query comes back blank - without any results.

Ofer said:
Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1



:

I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
J

John Spencer (MVP)

Close, but not quite. The user wanted to return the entire App_key (and
possibly other fields as well).

SELECT *
FROM WhatTable
WHERE Left([APP_KEY],9)
IN (SELECT Left([APP_KEY],9)
FROM WhatTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1)
Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1

R Layedra said:
I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
G

Guest

Hi John,

You're right on the money with what I want.

But, I still cannot come up with my desired result. I have created another
field where I have trimmed the APP_KEY to nine digits and that seems to work
but it's definately not what I wanted. Why is this simple (or so, it seems)
procedure so difficult to create?

Thanks for the help,

Rodolfo

John Spencer (MVP) said:
Close, but not quite. The user wanted to return the entire App_key (and
possibly other fields as well).

SELECT *
FROM WhatTable
WHERE Left([APP_KEY],9)
IN (SELECT Left([APP_KEY],9)
FROM WhatTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1)
Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1

R Layedra said:
I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
G

Guest

I don't know that this is necessarily the most efficient or best way to write
this, but it appears based on a quick test to work. My SQL looks like:

select * from testTbl
where left(keyFld, 9) in
(select distinct left(keyFld, 9) from testTbl
group by left(keyFld, 9)
having count(left(keyFld, 9)) > 1)
order by keyFld;

In general, my experience has been that when you are looking for duplicates
of something, you need to put the thing that is the duplicate in a table.
This is done courtesy of the nested select statement. The 'having' clause is
nested so that the table produced by the nested select only contains the keys
with duplicated left-most 9 characters.

--
Chaim


R Layedra said:
Hi John,

You're right on the money with what I want.

But, I still cannot come up with my desired result. I have created another
field where I have trimmed the APP_KEY to nine digits and that seems to work
but it's definately not what I wanted. Why is this simple (or so, it seems)
procedure so difficult to create?

Thanks for the help,

Rodolfo

John Spencer (MVP) said:
Close, but not quite. The user wanted to return the entire App_key (and
possibly other fields as well).

SELECT *
FROM WhatTable
WHERE Left([APP_KEY],9)
IN (SELECT Left([APP_KEY],9)
FROM WhatTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1)
Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1

:

I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 
G

Guest

Chaim,

Thanks so much for your assistance. I had already given up on this. I got
exactly what I was looking for!

Chaim said:
I don't know that this is necessarily the most efficient or best way to write
this, but it appears based on a quick test to work. My SQL looks like:

select * from testTbl
where left(keyFld, 9) in
(select distinct left(keyFld, 9) from testTbl
group by left(keyFld, 9)
having count(left(keyFld, 9)) > 1)
order by keyFld;

In general, my experience has been that when you are looking for duplicates
of something, you need to put the thing that is the duplicate in a table.
This is done courtesy of the nested select statement. The 'having' clause is
nested so that the table produced by the nested select only contains the keys
with duplicated left-most 9 characters.

--
Chaim


R Layedra said:
Hi John,

You're right on the money with what I want.

But, I still cannot come up with my desired result. I have created another
field where I have trimmed the APP_KEY to nine digits and that seems to work
but it's definately not what I wanted. Why is this simple (or so, it seems)
procedure so difficult to create?

Thanks for the help,

Rodolfo

John Spencer (MVP) said:
Close, but not quite. The user wanted to return the entire App_key (and
possibly other fields as well).

SELECT *
FROM WhatTable
WHERE Left([APP_KEY],9)
IN (SELECT Left([APP_KEY],9)
FROM WhatTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1)

Ofer wrote:

Try this query
SELECT Left([APP_KEY],9) AS Expr1
FROM MyTable
GROUP BY Left([APP_KEY],9)
HAVING Count(Left([APP_KEY],9))>1

:

I'm trying to find duplicates within a table where a field name called
APP_KEY is made up of 12 digits. However, I want the query to ONLY find
duplicates based on the first 9 digits: For example,
APP_KEY:
123456789001
123456789002
123456789003
123456789003
123456789003

I want the query to show me all FIVE records because they are all alike
within the first nine digits. I don't want just the last three!

Can anybody please help me? I've tried everything I can think of but my
access expertise is very limited.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top