Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / December 2004



Tip: Looking for answers? Try searching our database.

Sorting two columns as one?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ChuckWWW - 27 Dec 2004 15:58 GMT
Not sure how to approach this, but I've got course numbers (columns num and
multinum) that I'm selecting from two different tables (Courses and
MultiCourse).  I want to be able to sort the two different course number
columns as if they were a single column.  I know my order clause below isn't
the way to go because it will treat the second sort as subordinate.    Do I
handle concatinating these two fields for a single sort by manipulating the
original select statement (below), or perhaps there is a way I can concatinate
output the two fields to a new query and sort from there?  Thanks a bunch and
happy holidays,  Chuck ------------------- code snippet below
--------------------------  SELECT     majorcourse.title, Courses.num as num,
MultiCourse.multinum as multinum FROM         majorcourse INNER JOIN            
           courses ON majorcourse.courseid = coursesid                        
                                      full outer JOIN                          
                                     multiCourse ON multiCoursecourseid =
coursesid                          ORDER BY Courses.num,MultiCourse.multinum  
ChuckWWW - 28 Dec 2004 14:35 GMT
I solved this by populating a new query with the output of the first query, and
concatenating the two fields into one new column like so (in this case I only
care about getting the alternative column value if a certain switch value is
set to 1):  <cfset CountVar = 0> <cfset GetAllCourses =
QueryNew('courseid,title,coursenum')> <cfloop query='getCourses'> <cfset temp =
QueryAddRow(GetAllCourses)> <cfset countvar = countvar + 1> <cfset temp =
QuerySetCell(GetAllCourses, 'courseID', '#getCourses.courseid#', countvar)>
<cfset temp2 = QuerySetCell(GetAllCourses, 'title', '#getCourses.title#',
countvar)> <cfset temp3 = QuerySetCell(GetAllCourses, 'coursenum',
'#getCourses.num#', countvar)> <cfif multiswitch is 1 and getcourses.multinum
is not ''> <cfset temp3 = QuerySetCell(GetAllCourses, 'coursenum',
'#getCourses.multinum#', countvar)> </cfif>  </cfloop>
klchio - 29 Dec 2004 14:52 GMT
Or you can union two separate queries and sort the whole thing...

SELECT majorcourse.title, Courses.num as num,
FROM majorcourse INNER JOIN courses ON majorcourse.courseid = coursesid
UNION
SELECT '', MultiCourse.multinum
FROM multiCourse
WHERE multiCoursecourseid = coursesid
ORDER BY 2
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.