Question : Cfouput distinct items for a field

I have a table that I want to output into a series of drop down menus.  Each field has duplicate entries that cannot be removed.  Using a query I want to pull all of the data from the table at once.   I only want to display the distinct entries from each field.  I cannot use SELECT DISTINCT in the query though because all entries are distinct.  I need to be able to pull distinct fields and all data at the same time.    I put an example below that I hope explains what my table looks like a little better.

hierarchyID   domain                          directory     subdirectory      subdirectory2
1                   www.mysite.com          about            docs                 images      
2                   www.mysite.com          about            docs                 forms    
3                   www.mysite.com          about            contact
4                   www.mysite.com          forms          
5                   www.mysite.com          forms            images

My query is


SELECT  *
FROM hierarchy
ORDER BY hierarchyID ASC


I would like to display the distinct directory, subdirectory,...   For example I'll want to pull only subdirectories in the "about" directory.  As you can see in my example table above that there are duplicate entries under each field but the complete database entry is not a duplicate.   Is there a way to do something like DISTINCT(#directory#) so that I can just run the query once but output the distinct items?

Answer : Cfouput distinct items for a field

If you need to have the dropdowns update based on prior selections you will either need to use Javascript or AJAX.  The javascript route would preload all of the possible values to the browser, where AJAX would update each one real time.  You can find out more by researching "dynamic dropdown" with javascript or Coldfusion.

Now, if you don't need the dropdowns to update without a reload, then you can simply solve the problem with a query-of-query.  Query-of-queries read from the original query already loaded in memory so you don't have to run back to the database a second time.  For example, to get only the subdirectories for the "about" directory, here is the code:



SELECT  *
FROM hierarchy
ORDER BY hierarchyID ASC




SELECT subdirectory
FROM gethierarchy
WHERE directory = "about"
Random Solutions  
 
programming4us programming4us