473,508 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting rid of duplicates

I have a table, TEST_TABLE, with 6 columns (COL1, COL2, COL3, COL4,
COL5, COL6).... I need to be able to select all columns/rows where
COL3, COL4, and COL5 are unique....

I have tried using DISTINCT and GROUP BY, but both will only allow me
to access columns COL3, COL4, and COL5..... i need access to all
columns...I just want to get rid of duplicate rows (duplicates of
COL3, COL4, and COL5)...
Thanks in advance.

Joe
Jul 20 '05 #1
1 3148
If a row is duplicated on (col3, col4, col5) which values do you want for
col1 and col2?

Here's some example data:

CREATE TABLE Sometable (col1 INTEGER NOT NULL, col2 INTEGER NOT NULL, col3
INTEGER NOT NULL, col4 INTEGER NOT NULL, col5 INTEGER NOT NULL /* PRIMARY
KEY ??? */)

INSERT INTO Sometable VALUES (1,2,3,4,5)
INSERT INTO Sometable VALUES (2,1,3,4,5)

If you don't care which values go into col1 and col2:

SELECT MIN(col1) AS col1, MIN(col2) AS col2,
col3, col4, col5
FROM Sometable
GROUP BY col3, col4, col5

If you want just one row from the table for each value of (col3, col4,
col5):

SELECT MIN(S1.col1) AS col1, S1.col2, S1.col3, S1.col4, S1.col5
FROM Sometable AS S1
JOIN
(SELECT MIN(col2) AS col2, col3, col4, col5
FROM Sometable
GROUP BY col3, col4, col5) AS S2
ON S1.col2 = S2.col2
AND S1.col3 = S2.col3
AND S1.col4 = S2.col4
AND S1.col5 = S2.col5
GROUP BY S1.col2, S1.col3, S1.col4, S1.col5

Try out one of these two queries. If you need more help, please post DDL and
sample data (CREATE and INSERT statements as above) and show your required
result.

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2

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

Similar topics

11
1939
by: The Crow | last post by:
i have a arraylist. say it contains integer values. i want to be able to inform user, which indexes in the array contain same values. but there can be N different values, and M different indexes...
3
1256
by: Bob | last post by:
It's not especially important, but I always like to know the best way of doing things for when I encounter a case where performance becomes a factor... say I have a string array and I want to get a...
3
2163
by: AK | last post by:
Hi Our product uses MS-SQL Server 2000. One of our customer has 10 installations with each installation stroring data in its own database. Now the customer wants to consolidate these databases...
41
3109
by: pb648174 | last post by:
In a multi-user environment, I would like to get a list of Ids generated, similar to: declare @LastId int select @LastId = Max(Id) From TableMania INSERT INTO TableMania (ColumnA, ColumnB)...
7
3351
by: vsgdp | last post by:
I have a container of pointers. It is possible for two pointers to point to the same element. I want to remove duplicates. I am open to which container is best for this. I thought of using...
2
3226
by: Dave | last post by:
I'm in need of a little sql help. How do i get a list of ids from one table that do not have the same ids in another table? I hope that makes sense.
14
12947
by: ak | last post by:
Is it possible to find repeated(duplicate) element in an array in single loop ? AK
1
2134
by: tskmjk55 | last post by:
Recently, I have a requirement to develop a vb.net application wherein the input excel sheet data which has an average of 5000 records should be checked for Internal duplicates (duplicates within the...
3
25053
Thekid
by: Thekid | last post by:
I'm trying to figure out a way to find if there are duplicates in an array. My idea was to take the array as 'a' and make a second array as 'b' and remove the duplicates from 'b' using 'set' and then...
0
7231
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
7336
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,...
1
7063
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
7504
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...
1
5059
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
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
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 ...
1
773
muto222
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.