Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 5th, 2005, 11:05 AM
nluoma nluoma is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 5 nluoma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 32 sec
Reputation Power: 0
Select Distinct

I need to select the distinct Category values that appear in a table to use them to drive a loop processing the table contents. I need the categories to be sorted by first the Order field, and then the Category field. However, I can't figure out how to do this. If I pull the distinct values from the table itself:
sqlstr2 = "SELECT DISTINCT FAQsKB.category FROM FAQsKB WHERE FAQsKB." & group & " = True"
Set cats = dbs.OpenRecordset(sqlstr2, dbOpenDynaset)
I get each category listed once. However, they appear in alphabetical order of category.
If I pull the distinct values from a query that sorts the data the way I want it to be sorted, each category appears multiple times.
I've also tried sorting the table on the appropriate fields, but this has no effect on the output.
It's not possible to add an "Order by" statement to the Select distinct statement, unless it's to order by the category field. Which doesn't help. )
Anyone have an idea how I can get a list of just the distinct categories yet force them to be sorted as I want?
Thanks!

Reply With Quote
  #2  
Old April 5th, 2005, 01:44 PM
mvagh2 mvagh2 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 324 mvagh2 User rank is Corporal (100 - 500 Reputation Level)mvagh2 User rank is Corporal (100 - 500 Reputation Level)mvagh2 User rank is Corporal (100 - 500 Reputation Level)mvagh2 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 16 h 26 m 36 sec
Reputation Power: 5
Hi,


Try this:

Code:
 sqlstr2 = "SELECT DISTINCT FAQsKB.category FROM FAQsKB WHERE FAQsKB." & group & " = True ORDER BY Order, Category"
 

Michiel

Reply With Quote
  #3  
Old April 6th, 2005, 08:25 AM
nluoma nluoma is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 5 nluoma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 32 sec
Reputation Power: 0
Still not resolved

If I use the code exactly as typed, it results in a syntax error in the Order By clause.

If I modify the code to end ORDER BY FAQsKB.order, FAQsKB.category it results in an error stating that the Order By Order conflicts with distinct.


Quote:
Originally Posted by mvagh2
Hi,


Try this:

Code:
 sqlstr2 = "SELECT DISTINCT FAQsKB.category FROM FAQsKB WHERE FAQsKB." & group & " = True ORDER BY Order, Category"

Michiel

Reply With Quote
  #4  
Old April 6th, 2005, 08:32 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,181 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 19 m 32 sec
Reputation Power: 699
you must add the FAQsKB.order fied in your select part, to use it in the order statement

Code:
sqlstr2 = "SELECT DISTINCT FAQsKB.category,FAQsKB.order FROM FAQsKB WHERE FAQsKB." & group & " = True ORDER BY Order, Category"


hope this helps
__________________
Look! Its a ShemZilla



Reply With Quote
  #5  
Old April 6th, 2005, 09:00 AM
nluoma nluoma is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 5 nluoma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 32 sec
Reputation Power: 0
Yes! That seems to solve the problem! (Though I have to upload the XML to be sure it's working right...)

Thanks!

Quote:
Originally Posted by nofriends
you must add the FAQsKB.order fied in your select part, to use it in the order statement

Code:
sqlstr2 = "SELECT DISTINCT FAQsKB.category,FAQsKB.order FROM FAQsKB WHERE FAQsKB." & group & " = True ORDER BY Order, Category"


hope this helps

Reply With Quote
  #6  
Old April 6th, 2005, 12:35 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,181 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced FolderFolding Points: 98259 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 19 m 32 sec
Reputation Power: 699
no problem

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Select Distinct


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway