Solved

how can select distinct records within loop

Posted on 2004-04-20
7
373 Views
Last Modified: 2006-11-17
Since i can't do it with the distinct option, was wondering if there is a way to display a record
only once using a loop?
0
Comment
Question by:alberte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10870119
Why cant you use a dinstinct? What sql are you using??
0
 
LVL 11

Expert Comment

by:L00M
ID: 10870159
I assume you mean you've queried a database and now have a populated recordset.
For whatever reason, you can't use distinct in the query...

So, I would recommend converting the recordset to an array:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=161

Now that you have an array, sort it:
http://www.4guysfromrolla.com/webtech/012799-3.shtml

You could then enumerate through the array and check to see if the next row matches the previous row, if not copy the current row to an identical table.
If so, skip it and move on to the next until they don't match. At that point, copy the current row to the identical table, and set the new current row to the non matching row. (Confusing eh?)
In the end, your identical table will hold distinct results.
0
 

Author Comment

by:alberte
ID: 10870303
I don't think i will use an array, I finaly got a query to work but i get more records
then i need and i can't select distinct.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10870312
Can you show us the query?
0
 
LVL 6

Accepted Solution

by:
sforcier earned 50 total points
ID: 10870563
Does this do what you want?

Dim oldVal
oldVal = ""

While Not(rs.EOF)
   if rs("fieldname") <> oldVal then
      oldVal = rs("fieldname")
      'Show data, or whatever it is you want to do
   end if
   rs.MoveNext
Wend
0
 
LVL 6

Expert Comment

by:sforcier
ID: 10870582
BTW, my code assumes that the recordset is sorted based on the duplicated field. Otherwise it won't work... that's an important thing to point out! :)
0
 
LVL 5

Expert Comment

by:waelothman
ID: 10870709
select Filed1,Field2 , Min(Filed3) as MField3 , Min(Filed4) as MField4 from tablename
group by  Filed1,Field2

where field 1, Field2 is what u wat to be distincit by
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question