473,573 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

identify duplicates in an array and number of times duplicated

hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle

Jul 19 '05 #1
8 7804
If you've already sorted your array alphabetically, you can do:

Dim sCurVal, sLastVal, iDups
iDups = 0
For i = LBound(YourArra y) To UBound(YourArra y)
sCurVal = YourArray(i)
If sCurVal = sLastVal Then iDups = iDups + 1
sLastVal = sCurVal
Next
This will just give you the total number of duplicate items, like, if your
array is

a,b,c,c,d,e,e,e ,f,g

iDups will return as 3, since there is one extra c and two extra e's.

Is that what you wanted, or did you want to be able to say:
c has 1 duplicate
e has two duplicates
etc.

Ray at work

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle

Jul 19 '05 #2
Why not do a count in the SQL query string and get the username and count from the recordset?

-------------------------------------------------
d l b j r

Unambit from meager knowledge of inane others,
engender uncharted sagacity.
-------------------------------------------------
Jul 19 '05 #3
You'd be better off getting another recordset with the duplicate counts
already created for you?

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
GROUP BY [Name]
ORDER BY Count([Name]) DESC

This will give you:

UserName CountOfUserName
Chris 10
Dave 7
Henrik 2
Michale 1
Joan 1

etc.

If you only want the duplicates listed then change it to be:

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
WHERE Count([Name]) > 1
GROUP BY [Name]
ORDER BY Count([Name]) DESC

Hope this helps.

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle


Jul 19 '05 #4
Hi Ray
Is that what you wanted, or did you want to be able to say:
c has 1 duplicate
e has two duplicates
Yes this is what i want

I tried to use your code, although i had to add 'end if', it gave me a
a 'Subscript out of range' error atsCurVal = YourArray(i)
----------------------------------------------
this is my code for the array
----------------------------------------------
<%
Dim MyArray, sOutput
MyArray = rs.GetRows()
MyArray = arraysort(MyArr ay)

Dim iRowLoop
For iRowLoop = 0 to UBound(MyArray, 2)
sOutput = trim(left(MyArr ay(iColLoop, iRowLoop),10)) & "<br> "
Response.Write( sOutput)
Next
%>
----------------------------------------------

Actually the rows in the array is unique, the source is a text file dump of
terminal service processes, but i need to extract the user names of those
using a particular process twice, and how many times they have these
processes open. I cannot sort or search for duplicates in SQL, because the
first line contains a lot of spaces inbetween the headings which dosnt make
a qualified column name.

Hope you can help.

--
Michelle
"Ray at <%=sLocation% >" <myfirstname at lane34 dot com> wrote in message
news:#C******** ******@TK2MSFTN GP12.phx.gbl... If you've already sorted your array alphabetically, you can do:

Dim sCurVal, sLastVal, iDups
iDups = 0
For i = LBound(YourArra y) To UBound(YourArra y)
sCurVal = YourArray(i)
If sCurVal = sLastVal Then iDups = iDups + 1
sLastVal = sCurVal
Next
This will just give you the total number of duplicate items, like, if your
array is

a,b,c,c,d,e,e,e ,f,g

iDups will return as 3, since there is one extra c and two extra e's.

Is that what you wanted, or did you want to be able to say:
c has 1 duplicate
e has two duplicates
etc.

Ray at work

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle


Jul 19 '05 #5
Re:
I cannot sort or search for duplicates in SQL, because the
first line contains a lot of spaces in-between the headings which doesn't
make
a qualified column name.

That doesn't seem to make sense - in order to get a recordset you must be
specifying some SQL? You can determine the 'real' field names by enumerating
the fields collection or just use the numeric field indexes 0 to however
many fields.

eg. SELECT TOP 1 * FROM Table

will get a single row recordset that you can look at to get the field names.

However, you know what you have so I'll stop there and let you decide what's
easiest to implement (array manipulation or SQL).

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
Please see reply to Ray

--
Michelle

"Chris Barber" <ch***@blue-canoe.co.uk.NOS PAM> wrote in message
news:OW******** ******@TK2MSFTN GP12.phx.gbl...
You'd be better off getting another recordset with the duplicate counts
already created for you?

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
GROUP BY [Name]
ORDER BY Count([Name]) DESC

This will give you:

UserName CountOfUserName
Chris 10
Dave 7
Henrik 2
Michale 1
Joan 1

etc.

If you only want the duplicates listed then change it to be:

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
WHERE Count([Name]) > 1
GROUP BY [Name]
ORDER BY Count([Name]) DESC

Hope this helps.

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle


Jul 19 '05 #6
Hi Chris

This is the SQL i am using
sql="SELECT * from process.txt"
process.txt is a text file dumped from ms-dos and this is the first 6 lines
from this file
--------------------------------------------------------
USERNAME SESSIONNAME ID PID IMAGE
davidp id 1 1 3472 notepad.exe
davidp id 9 9 4348 notepad.exe
evenf id 8 8 5160 notepad.exe
patricka id 19 19 7904 notepad.exe
rebeccah id 10 10 2820 notepad.exe
--------------------------------------------------------
since this file isnt delimited, all this data is retrieved into one column
and the first line contains spaces, so i cannot do

sql="SELECT 'USERNAME SESSIONNAME ID PID IMAGE'
from process.txt"
or any other sql statement that requires i directly name the column
You can determine the 'real' field names by enumerating
the fields collection or just use the numeric field indexes 0 to however how can i do this in ASP?

I want to be able to show that davidp is using a program twice
eg. davidp (2)

--
Michelle
"Chris Barber" <ch***@blue-canoe.co.uk.NOS PAM> wrote in message
news:uv******** ******@tk2msftn gp13.phx.gbl... Re:
I cannot sort or search for duplicates in SQL, because the
first line contains a lot of spaces in-between the headings which doesn't
make
a qualified column name.

That doesn't seem to make sense - in order to get a recordset you must be
specifying some SQL? You can determine the 'real' field names by enumerating the fields collection or just use the numeric field indexes 0 to however
many fields.

eg. SELECT TOP 1 * FROM Table

will get a single row recordset that you can look at to get the field names.
However, you know what you have so I'll stop there and let you decide what's easiest to implement (array manipulation or SQL).

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
Please see reply to Ray

--
Michelle

"Chris Barber" <ch***@blue-canoe.co.uk.NOS PAM> wrote in message
news:OW******** ******@TK2MSFTN GP12.phx.gbl...
You'd be better off getting another recordset with the duplicate counts
already created for you?

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
GROUP BY [Name]
ORDER BY Count([Name]) DESC

This will give you:

UserName CountOfUserName
Chris 10
Dave 7
Henrik 2
Michale 1
Joan 1

etc.

If you only want the duplicates listed then change it to be:

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
WHERE Count([Name]) > 1
GROUP BY [Name]
ORDER BY Count([Name]) DESC

Hope this helps.

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle


Jul 19 '05 #7
Hi All

Thank you for your inputs, but i have solved my problem,
i didnt ask the right question in the beginning, what i needed was
to search a string for duplicates and the number of times the value
had been duplicated.

But what i had was, an array of unique values, which i manipulated
and displayed to show some duplicates.

Thanks again.
--
Michelle
"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle

Jul 19 '05 #8
Perhaps this is space or fixed width delimited?
It is possible to query a text file that is space or fixed width delimited
by column names but I'm pretty sure you're already aware of that and may
even have tried it.

Cheers,

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
Hi Chris

This is the SQL i am using
sql="SELECT * from process.txt"
process.txt is a text file dumped from ms-dos and this is the first 6 lines
from this file
--------------------------------------------------------
USERNAME SESSIONNAME ID PID IMAGE
davidp id 1 1 3472 notepad.exe
davidp id 9 9 4348 notepad.exe
evenf id 8 8 5160 notepad.exe
patricka id 19 19 7904 notepad.exe
rebeccah id 10 10 2820 notepad.exe
--------------------------------------------------------
since this file isnt delimited, all this data is retrieved into one column
and the first line contains spaces, so i cannot do

sql="SELECT 'USERNAME SESSIONNAME ID PID IMAGE'
from process.txt"
or any other sql statement that requires i directly name the column
You can determine the 'real' field names by enumerating
the fields collection or just use the numeric field indexes 0 to however how can i do this in ASP?

I want to be able to show that davidp is using a program twice
eg. davidp (2)

--
Michelle
"Chris Barber" <ch***@blue-canoe.co.uk.NOS PAM> wrote in message
news:uv******** ******@tk2msftn gp13.phx.gbl... Re:
I cannot sort or search for duplicates in SQL, because the
first line contains a lot of spaces in-between the headings which doesn't
make
a qualified column name.

That doesn't seem to make sense - in order to get a recordset you must be
specifying some SQL? You can determine the 'real' field names by enumerating the fields collection or just use the numeric field indexes 0 to however
many fields.

eg. SELECT TOP 1 * FROM Table

will get a single row recordset that you can look at to get the field names.
However, you know what you have so I'll stop there and let you decide what's easiest to implement (array manipulation or SQL).

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
Please see reply to Ray

--
Michelle

"Chris Barber" <ch***@blue-canoe.co.uk.NOS PAM> wrote in message
news:OW******** ******@TK2MSFTN GP12.phx.gbl...
You'd be better off getting another recordset with the duplicate counts
already created for you?

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
GROUP BY [Name]
ORDER BY Count([Name]) DESC

This will give you:

UserName CountOfUserName
Chris 10
Dave 7
Henrik 2
Michale 1
Joan 1

etc.

If you only want the duplicates listed then change it to be:

SELECT [Name] as UserName, Count([Name]) as CountOfUserName
FROM YourTable
WHERE Count([Name]) > 1
GROUP BY [Name]
ORDER BY Count([Name]) DESC

Hope this helps.

Chris.

"Michelle" <ab*@hotmail.co m> wrote in message
news:3f******** *************** @news.optusnet. com.au...
hi,

i have created an array from recordset containing user names
eg. (davidp, davidp, evenf, patricka, rebeccah)

which i have sorted in alphabetical order, but i need to
identify duplicates in this array and the number of times it has
been duplicated.

can someone help?

--
Michelle



Jul 19 '05 #9

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

Similar topics

8
487
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I get this exception: "Cannot insert duplicate key row in object 'tblTelephones' with unique index 'UniqueValues'." What I'm looking for is a way...
6
2383
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec Qty Invoice# Item Supplier Status POReceivedDate 570133 03/09/2004 50 0 DMEDIUM L0010 PENDING 03/09/2004...
1
420
by: Themba via AccessMonster.com | last post by:
I have a table with two columns.it's a unique number and the vendor name. Number vendor 001 spar 002 spar 003 heckers 004 donald 005 donald what i want to do is to run select a query that will only show me the
4
2468
by: Killer42 | last post by:
Hi all. Sorry, this is probably a really simple one but I'm having some difficulty with it, and don't have much time to devote to it right now. I need to find all the records which have duplicates (on two fields) in another table. In Access 2003, the "Find duplicates wizard" will produce a query to list duplicates within the one table, but...
14
12953
by: ak | last post by:
Is it possible to find repeated(duplicate) element in an array in single loop ? AK
2
5414
by: Radu | last post by:
Hi. I have a "union" table which results of a union of two tables. Occasionally I could have duplicates, when the same PIN has been added to both tables, albeit at different Datees/Times, such as: PIN Name Added Date 100411 A 7/11/2007 10:12:58 AM 100411 A 7/17/2007 10:54:23 AM 100413 B 7/11/2007 10:13:28 AM
16
3480
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate...
3
2838
by: ryan.paquette | last post by:
In the table there are 2 fields in which I wish to limit (i.e. No Duplicates) Although I do not want to limit them to "No Duplicates" separately. I need them to be limited to "No Duplicates" as if they were one field. The 2 fields are "Employee_Name" & "Training_Course". *(There is another table for Employees & another for Training...
2
2114
by: chemlight | last post by:
I'm trying to figure out how to order an array based on the number of duplicates, and then remove all duplicates. This is my code right now: foreach($acID as $searchterms){ $results = mysql_query(SELECT * FROM table WHERE field LIKE '%$searchterms%') while($row = mysql_fetch_array($results)){
0
8009
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8198
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7771
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8060
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6406
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5580
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5289
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3730
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2194
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 we have to send another system

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.