Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how can select distinct records within loop

Posted on 2004-04-20
7
Medium Priority
?
374 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 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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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