how can select distinct records within loop

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?
alberteAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sforcierConnect With a Mentor Commented:
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
 
SlimshaneeyCommented:
Why cant you use a dinstinct? What sql are you using??
0
 
L00MCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
alberteAuthor Commented:
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
 
SlimshaneeyCommented:
Can you show us the query?
0
 
sforcierCommented:
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
 
waelothmanCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.