473,472 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SELECT DISTINCT: remove duplicates when not all fields match, but display everything

3 New Member
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 table (All Illumina ITPR3), but the rest of the fields don't necessarily match (Haplotype, DR genotype).

If I run SELECT DISTINCT on "Indiv ID", I can't get the other fields to be displayed. If I run SELECT DISTINCT on all the fields I want (Indiv ID, Haplotype, DR genotype), then I still get duplicate ID's, because it wants to match on all three fields.

Is there a good way to have it not display the duplicate ID records (and not require that all fields match) but display all my other fields?

It would be awesome if I could get a result by Tuesday morning, so I could use this at work tomorrow, but this isn't extremely urgent.

Thanks!
Erin

SELECT [All Illumina ITPR3].[Indiv ID], [All Illumina ITPR3].Haplotype, [All Illumina ITPR3].[DR genotype]
FROM [All Illumina ITPR3], [DAISY Individuals DR and DP Typing];
Nov 27 '06 #1
6 10335
NeoPa
32,556 Recognized Expert Moderator MVP
I'm thinking about your question. If it makes sense it can be done - I'll get straight back to you.
In the mean time your query :
Expand|Select|Wrap|Line Numbers
  1. SELECT [All Illumina ITPR3].[Indiv ID], [All Illumina ITPR3].Haplotype, [All Illumina ITPR3].[DR genotype]
  2. FROM [All Illumina ITPR3], [DAISY Individuals DR and DP Typing];
only seems to get data from one table yet two are listed :s.
This will cause duplicates (assuming more than one record in the unused table.
It seems you can tidy the SQL up to :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Indiv ID], Haplotype, [DR genotype]
  2. FROM [All Illumina ITPR3];
Nov 27 '06 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Is there a good way to have it not display the duplicate ID records (and not require that all fields match) but display all my other fields?
I've thought about it and realised you're asking for the impossible. Not difficult you understand, actually nonsensical.
What could it display for the other fields if you request a unique ID?

Now, if you weren't requiring the actual values but were happy with any example value, then you could use GROUP BY with First(). In case this is acceptable the SQL you want is :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Indiv ID],
  2.   First(Haplotype) AS 1stHaplotype,
  3.   First([DR genotype]) AS [1stDR genotype]
  4. FROM [All Illumina ITPR3]
  5. GROUP BY [Indiv ID];
Nov 27 '06 #3
pooh80133
3 New Member
Thanks-I will eventually draw data from two tables, which is why both are listed. The duplicate "records" are actually in the one table, "All Illumina ITPR3." In this table, I have more than one record per Indiv ID, but the information I need is listed in both records (hence wanting to only list it once and get rid of the duplicate). I can't just delete the records in my table, because there is some important data in both rows.

Thanks for checking into it for me!
Erin
Nov 27 '06 #4
NeoPa
32,556 Recognized Expert Moderator MVP
The important question isn't about handling duplicates (where all fields are the same), but how to handle records with duplicate ID but different data. I can't stress enough how important that concept is.
I hope I've helped anyway.
Nov 27 '06 #5
pooh80133
3 New Member
Thanks for the help-I just figured out what I needed to do. I was trying to make the query display data from the fields that varied between the two records with the same ID. However, if I just put in the fields that are invariant, using a SELECT DISTINCT, it works!

Thanks for clearing that up!

Erin

Here is my new code (with different, invariant fields):

Expand|Select|Wrap|Line Numbers
  1. ..SELECT DISTINCT [All Illumina ITPR3].[Indiv ID], [All Illumina ITPR3].[rs2229634 genotype], [DAISY Individuals DR and DP Typing].DPB_1
  2. FROM [All Illumina ITPR3] LEFT JOIN [DAISY Individuals DR and DP Typing] ON [All Illumina ITPR3].[Indiv ID] = [DAISY Individuals DR and DP Typing].[Indiv ID];..
Nov 27 '06 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Sorry Erin. I'd picked up from your first post that you already understood that.
May I make a design concept suggestion.
Naming can be more important than people realise and long, involved names do cause problems.
Anything with embedded spaces cause []s to be mandatory. Long names cause SQL to be hard to understand easily when reading.
These things sound like style issues but they're really not. Usage and understanding will be much easier if short 'spaceless' names are used. Always use enough to relay what it's being used for though. Like most things in life it comes down to balance.

Anyway I'm glad you've got it sorted and understood now :).
Nov 27 '06 #7

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

Similar topics

4
by: Marco Alting | last post by:
Hi I have two table which are related: table1 holds personellinformation table2 holds nodeInformation The nodes in table2 can have a nodeOwner which will then get a recordID from table1. A...
3
by: Cindy | last post by:
OK, I have the following table: create table citations_by_level ( aid smallint, wid smallint, v_level varchar(50), w_level varchar(50), x_level varchar(50), y_level varchar(50),
9
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my...
8
by: skinnybloke | last post by:
Hi - I have a problem with a memo field being truncated to about 255 characters when running a Access 2002 query. This only seems to happen if I use SELECT DISTINCT. It works ok using SELECT by...
4
by: Ben | last post by:
I believe I am missunderstanding how subqueries work. I simple subquery works fine but when I wish do compare 2 or more fields at once I don't get the results I wish. Table A...
18
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are...
6
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table ...
2
by: Genalube | last post by:
I am running a query that includes the inclusion of memo fields, my query pulls from four different tables with one to many relationships between them. The relationships are such that when I run my...
9
by: P3Eddie | last post by:
Hello all! I don't know if this can even be done, but I'm sure you will either help or suggest another avenue to accomplish the same. My problem may be a simple find duplicates / do something...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
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
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.