User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,529 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,754 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 3979 | Replies: 3
Reply
Join Date: Aug 2004
Posts: 4
Reputation: chock is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chock chock is offline Offline
Newbie Poster

How to list the record orderby id when selecting distinct

  #1  
Aug 11th, 2004
Hai ,

i am getting the correct result for the below query

rs.Open "SELECT DISTINCT RepTL From PEList WHERE RepFL='" & CriteriaName & "'", Cnn, adOpenStatic, adLockReadOnly, adCmdText

but the thing is i need to display the record in the Order by RepId, but when i add RepId in the query its shows more records and not the distinct RepTL when i write as below


rs.Open "SELECT DISTINCT RepTL,RepId From PEList WHERE RepFL='" & CriteriaName & "'", Cnn, adOpenStatic, adLockReadOnly, adCmdText

what is the way to display the records order by Id and the RepTL should be distinct.

Kindly suggest me.

Thank you,
Chock.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 191
Reputation: mnemtsas is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: How to list the record orderby id when selecting distinct

  #2  
Aug 11th, 2004
Originally Posted by chock
Hai ,

i am getting the correct result for the below query

rs.Open "SELECT DISTINCT RepTL From PEList WHERE RepFL='" & CriteriaName & "'", Cnn, adOpenStatic, adLockReadOnly, adCmdText

but the thing is i need to display the record in the Order by RepId, but when i add RepId in the query its shows more records and not the distinct RepTL when i write as below


rs.Open "SELECT DISTINCT RepTL,RepId From PEList WHERE RepFL='" & CriteriaName & "'", Cnn, adOpenStatic, adLockReadOnly, adCmdText

what is the way to display the records order by Id and the RepTL should be distinct.

Kindly suggest me.

Thank you,
Chock.

How can you order by RepID and have the DISTINCT clause on RepTL? Lets say you have two records with RepTL="foo", one with RepID=8 and the other with RepID=12. How does the distinct query know what RepID to use? So, of course it will put a record for both, and thus your distinct clause is rendered useless.

I think you need to rethink what you are trying to do.

Mark
Reply With Quote  
Join Date: Aug 2004
Posts: 4
Reputation: chock is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chock chock is offline Offline
Newbie Poster

Re: How to list the record orderby id when selecting distinct

  #3  
Aug 11th, 2004
Hai Mark,

I know what i am doing is not correct, should i use subquery or what, can u suggest me.

Thank you,
chock.
Reply With Quote  
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 191
Reputation: mnemtsas is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: How to list the record orderby id when selecting distinct

  #4  
Aug 11th, 2004
Hi There,

Try doing it manually,

Something like:

Select RepTL,RepID From PEList WHERE RepFL='foo' ORDER BY RepTL ASC, RepID DESC;

Then loop through the record set taking note of when RepTL changes and recording RepID which is the highest ID (or change the sort order). Something like:
strLastRepTL=""
Do
  if strLastRepTL<>rs.fields("RepTL").value then
    debug.print "New LastRepTL found, RepID-" & rs.fields("RepID").value
    strLastRepTL=rs.fields("RepTL").value
  endif
  rs.MoveNext
Loop until rs.eof

Cheers,

Mark
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 4:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC