473,405 Members | 2,310 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,405 software developers and data experts.

Access 2010 query duplicates

Hello,

I have following problem:

table1
id / ArticleCode / ArticleColor
1 / 123 / blue
2 / 123 / blue
3 / 222 / green
4 / 333 / red
5 / 444 / blue

Out of this data I need to pick unique values to return:

1 / 123 / blue
3 / 222 / green
4 / 333 / red
5 / 444 / blue

so basically, i need to keep all the fields, but throw out only records that have duplicate ArticleCode

When I run a wizard to find duplicates, and include ID and ArticleColor, it returns all recods.

When I use COUNT([ArticleCode])=1 it returns only record w/o duplicates.


Please help me out
Feb 8 '13 #1

✓ answered by Narender Sagar

If I have to solve this, I'd simply create following query :
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.COLOR, Table1.CODE, First(Table1.ID) AS FirstOfID
  2. FROM Table1
  3. GROUP BY Table1.COLOR, Table1.CODE;
I tried above query and got desired result..

10 2037
Seth Schrock
2,965 Expert 2GB
You need a SELECT DISTINCT query.

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM table1
Feb 8 '13 #2
zmbd
5,501 Expert Mod 4TB
Respectfully Seth, That will not work, nor will "DISTINCTROW" in that the field [ID] contains a unique value. You really should try it in a test database, don't take my word for it... ;-)

Now, if OP does not need [ID] then you can include only the [ArticleCode] and [ArticleColor] in the query use either of the "DISTINCT" Predicates.
Feb 8 '13 #3
Thanks for reply,

Expand|Select|Wrap|Line Numbers
  1. select distinct *
  2. from table1

still will return all the records because of unique ID

If I only SELECT DISTINCT on ArticleCode then ok, but problem is that I need the ID.

What Now?
Feb 8 '13 #4
zmbd
5,501 Expert Mod 4TB
AH, Thank You for attempting the SQL.
You really should read my post. It would have saved you some frustration.

I have one solution that I use quite often for things like this... took me ages to figure out and as it is not straight forward try the following:

I actually have a template table and query set for this:

tbl_test
PK is the primary key,
Expand|Select|Wrap|Line Numbers
  1. SELECT [test_PK], 
  2.    [Test_Field1], 
  3.    [Test_Field2]
  4. FROM [tbl_test] AS  t1
  5. WHERE NOT EXISTS 
  6.    (SELECT 1
  7.     FROM [tbl_test] AS t2
  8.     WHERE [t2]![test_field1] = [t1]![test_field1]
  9.          AND 
  10.                [t2]![test_field2] = [t1]![test_field2]
  11.          AND
  12.               [t2]![test_pk] <[t1]![test_pk]);
Now I hope Rabbit or NeoPa have something more elegant :)
Feb 8 '13 #5
Seth Schrock
2,965 Expert 2GB
Duh. I'm not sure what I was thinking, but I clearly missed the ID field throwing off the DISTINCT query results.
Feb 8 '13 #6
Narender Sagar
189 100+
If I have to solve this, I'd simply create following query :
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.COLOR, Table1.CODE, First(Table1.ID) AS FirstOfID
  2. FROM Table1
  3. GROUP BY Table1.COLOR, Table1.CODE;
I tried above query and got desired result..
Feb 8 '13 #7
zmbd
5,501 Expert Mod 4TB
Told you there had to be a better method for your data set... the query I posted is a much shorter one I use against 16 fields... it's an old database that was not designed very well by one of my predecessors; however, given what it does, it's impressive (but slow).
I never thought to re-work it for smaller datasets...
Feb 8 '13 #8
Wow. Problem Solved! Thanks
Feb 8 '13 #9
Narender Sagar
189 100+
If you post what solves your problem, it will be beneficial for other readers.
thanks.
Feb 8 '13 #10
NeoPa
32,556 Expert Mod 16PB
Narender:
If you post what solves your problem, it will be beneficial for other readers.
I suspect you misunderstand. My understanding from reading through the thread is that your post (which I've now selected as Best Answer) was exactly the breakthrough they were looking for.

@Jacejwbak.
I hope you noted that many experts were confused by your question asking for one thing, then indicating with the example something quite different. Seth actually answered the question perfectly, but that wasn't what you needed because the question was asked wrong. Typically, the clearer the question is, the quicker and more easily you will find an answer posted.
Feb 10 '13 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: phill86 | last post by:
Hi, I have an access 2010 database that I want to convert to an SQL Server database and I need to know if the data macros in access will still work in the SQL database or will i have to create...
5
by: jaad | last post by:
Hello, I have a database that was written in access 2007 on my pc. I wanted to work off site with the database so I uploaded it onto my laptop which is loaded with access 2010 beta. When I...
2
by: sierra7 | last post by:
It seems Access 2010 is associating an 'input mask' or field type with a combo box when a form is opened, even though there is no Format setting on the control. I have a form which has been...
2
by: dougancil | last post by:
I have a user who had deleted some records from a database today using Access 2010. They have an ID field that's autonumbered. They have No Duplicates allowed. When they created a new record today,...
0
by: Andolino | last post by:
In Access 2010 I get a Write Conflict error - "This record has been changed by another user..." In Access 2007 this Code is working - why? Private Sub Form_BeforeUpdate(Cancel As Integer) Dim...
1
by: Alan Yim | last post by:
Hi folks, My company recently upgraded our Office suite from 2003 to 2010. The problem in particular is with an Access database that was originally designed in Access 2003. The code in question...
5
by: colsoft | last post by:
I am using Access 2010. Am generating reports for the records, one record per page. The records on the even pages have a light black background shading which appears when am printing. Please i need...
2
by: Bill Boord | last post by:
I need to be able to shut off the AutoCorrect "feature" within Access 2010 code. I have utilized Application.SetOption with method strings for other startup requirements, but I cannot seem to find a...
1
dsatino
by: dsatino | last post by:
I have numerous applications built in Access 2000/2003 that all use ODBCdirect workspaces to access various non-Access databases. Unfortunately, ODBCdirect is 'no longer supported'in Access 2010 and...
1
by: Music Man | last post by:
Greetings All: I built a database in Microsoft SQL Server 2000 and used Microsoft Access 2010 as the front end. The database is used to keep track of "issues" that rise out of my employment. ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.