Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how can select distinct records within loop

Posted on 2004-04-20
7
Medium Priority
?
376 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
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
Industry Leaders: 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 150 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

Industry Leaders: 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!

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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