473,387 Members | 1,540 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,387 software developers and data experts.

Need SQL query to eliminate duplicates but save raw order

GB
Hello:
I have a table like this:

ID | AccNo
--------------------------------
1 0059
2 0059
3 0059
4 0194
5 0194
6 0067
7 0067
8 0067

I need a sql query to eliminate duplicates but save the raw order, like
this:

ID | AccNo
--------------------------------
1 0059
2 0194
3 0067

DISTINCT AccNo or GROUP BY AccNo HAVING COUNT(*) > 1 doesn't work for me
because it returns ordered result.

Thanks,
GB
Nov 13 '05 #1
1 1397
"GB" <v7****@hotmail.com> wrote in message
news:JHf9d.38864$N%.33473@edtnps84...
Hello:
I have a table like this:

ID | AccNo
--------------------------------
1 0059
2 0059
3 0059
4 0194
5 0194
6 0067
7 0067
8 0067

I need a sql query to eliminate duplicates but save the raw order, like
this:

ID | AccNo
--------------------------------
1 0059
2 0194
3 0067

DISTINCT AccNo or GROUP BY AccNo HAVING COUNT(*) > 1 doesn't work for me
because it returns ordered result.

Thanks,
GB

delete *
from accounts as a
where
(
select count(*) from accounts a2
where a2.AccNo = a.AccNo
and a2.ID <= a.ID
) > 1




Nov 13 '05 #2

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

Similar topics

3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
5
by: Alexander Korovyev | last post by:
Suppose I have two tables: CREATE TABLE Tab1 ( NOT NULL, NOT NULL, NOT NULL, NOT NULL) CREATE TABLE Tab2 ( NOT NULL,
3
by: Tony Young | last post by:
Hi, I have a multimap container. I want to eliminate all "duplicate" elements. By duplicate I mean something like (3, 4), (4, 3) and (4, 3), in which I want to eliminate any two of these...
2
by: Sebastian | last post by:
The following query needs about 2 minutes to complete (finding dupes) on a table of about 10000 addresses. Does anyone have an idea on how to speed this up ? Thanks in advance !!! Sebastian
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
2
by: M.Stanley | last post by:
Hi, I have a problem..I'm doing a specific query where I'm joining fields from a table with appednded data (there are duplicate records, except for the date/time), and another query. I want the...
5
by: Lyn | last post by:
This one is difficult to explain, so I will cut it down to the basics. I have a major table 'tblA' which has an autonum field 'ID-A' as primary key (of no significance to users). 'tblA' contains...
3
by: Sim Zacks | last post by:
I am using 8.0 beta 1 on an RH 8 Linux server. I have a union query that I am converting from access (where it worked) and it is returning duplicates. The only difference between the two rows is...
12
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.