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

SQL Help: Select distinct

Hi all,

This I thought would be a relatively easy question, but after hunting around the net, I haven't been able to source an answer..

I have a large table in Access with four fields.

I would like to generate a result set that includes all four columns,
but removes duplicates for the last 3 columns. eg:

something like

SELECT Column1, DISTINCT Column2, DISTINCT Column3, DISTINCT Column4 from Table_X;

can anyone help with the format ?

Note: Don't care what the value for Column1 is as long as it comes from one of the duplicates...

cheers,
Matt.
May 3 '07 #1
4 3203
select col1, col2, col3, col4
from tbl
group by col1

or it may be the other way round

group by col2,col3,col4

you get the drift.
May 3 '07 #2
select col1, col2, col3, col4
from tbl
group by col1

or it may be the other way round

group by col2,col3,col4

you get the drift.
Thanks for the response.

Unfortunately in order to use GROUP BY, I need to iclude all of the fields selected in the GROUP BY clasue which defeats the purpose...

ie. tried SELECT Column1, Column2, Column3, Column4 from Table_X GROUP BY Column2, Column3, Column4;

but got "You tried to execute a query that does not include the specified expression "Column1" as part of an aggregate function. (Error 3122)"


regards,
Matt.
May 3 '07 #3
Rabbit
12,516 Expert Mod 8TB
You'll need two queries. One to select distinct on all fields. A second to right join the query back with the original table on the first field.
May 3 '07 #4
NeoPa
32,556 Expert Mod 16PB
I would like to generate a result set that includes all four columns, but removes duplicates for the last 3 columns.
What do you mean by removing duplicates for the three columns?
What if there are duplicates in Coluimn B but attached to records where Column C is unique?

Perhaps you could provide some example data with your explanation, as well as the results you would require to be returned.
May 5 '07 #5

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

Similar topics

4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
3
by: Andrew | last post by:
Hi, I have a problem I would really appreciate help with. I am generating dynamic SQL and need to optimise it. The specific example I am trying to optimise looks like this: SELECT DISTINCT...
3
by: phillip.s.powell | last post by:
Is this how it's done? INSERT INTO student ( (SELECT DISTINCT a.* FROM student_spring a, student_summer b WHERE a.unique_key != b.unique_key)\ UNION (SELECT DISTINCT b.* FROM student_summer...
0
by: hahahardididi | last post by:
Hi Forums, I have a frustrating problem on my Stored Procedure. It can only proccess about 100 records in 10 minutes. I have 2 million initial records that need to processed. Meaning that with...
2
by: Matt Bob | last post by:
Thanks in advance for any help... I have a single table: Employees: Name DOB startdate dept ---------|----------|-------------|------------ Al 1/1/1940 4/5/2003 ...
10
by: Bob Bedford | last post by:
Hi all, I've ever the same problem. Table1 idperson, name, zip table2 zip, city, region.
10
by: mscurto | last post by:
What is the syntax for an sql command to get the following. I want to pull in a handful of fields from a table but one of the fields needs to be unique. For example, if I have a customer table...
1
by: Webstorm | last post by:
Hi, I hope someone can help me sort this out a bit, Im completely lost. Here is the page I am working on: http://www.knzbusinessbrokers.com/default.asp I have 3 search critera that I need to...
0
by: davidsavill | last post by:
Hi All, I am migrating a database from Firebird/Interbase to DB2 and have having issues with the stored procedures/functions. I have a number of functions that loop over a FOR loop, each pass...
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
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.