Order By or sorting nested querys

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Order By or sorting nested querys

    Hi,

    I have this code for example

    <cfquery name="rsRights" datasource="cf_db">
    SELECT RID, UID, PID FROM tbRights WHERE PID = #URL.PID#
    </cfquery>

    <cfloop query="rsRights">
    <cfquery name="rsUsers" datasource="cf_db">
    SELECT UID, UfirstName, UlastName FROM tbUsers WHERE UID =
    <cfoutput>#rsRights.UID#</cfoutput>
    </cfquery>

    <cfoutput>#rsUsers.UfirstName#</cfoutput>&nbsp;<cfoutput>#rsUsers.UlastName#</cf
    output>
    </cfloop>

    Now because it is the rsRights query that I am looping how do make an ORDER BY
    for the rsUsers? Because it does not help to put Order By in the rsUsers Query!
    or do I have the wrong approch on this?

    Regards
    Martin

    ICI-MASA Guest

  2. Similar Questions and Discussions

    1. Sorting a recursive table by specified order
      Hi all, I've got an table like this: TABLE: id int(8) PRIMARY AUTO_INCREMENT name varchar(80) parent int(8) INDEX order ...
    2. Weird sorting order when cflooping complex structures
      I use a complex structure like this: <cfset Application.nodeList = StructNew()> <cfset Application.nodeList.item1 = 'Status'> <cfset...
    3. Sorting the nested HierarGrid by Denis Bauer
      Hi, I am using Denis Bauers HierarGrid and would like to sort the nested grid. However each time I do that, I get the error message: Please...
    4. Sorting by alphabetical order
      I am doing a troubleshooting section in a manual and I would like to sort the problems under that section by alphabetical order. What do I do to sort...
    5. datagrid sorting - Reflection.Assembly.Load - Nested WebControls
      Hi, I am using reflection to load strong name custom webcontrols from the GAC. Control names are fed from a database to dynamically render...
  3. #2

    Default Re: Order By or sorting nested querys

    Hi

    can u try like this:

    <cfloop query="rsRights">
    <cfquery name="rsUsers" datasource="cf_db">
    SELECT UID, UfirstName, UlastName FROM tbUsers WHERE UID =
    <cfoutput>#rsRights.UID#</cfoutput> order by UID
    </cfquery>
    </cfloop>

    Is this what you want?
    on which field you want to sort and in which table it is.

    vkunirs Guest

  4. #3

    Default Re: Order By or sorting nested querys

    Hi,

    sorry i forgot to say that the field I wanted to sort is UfirstName, and I
    tried to place a order by UfirstName where you placed the order by UID but that
    doesnt work, because I guess the loop is for the rsRights query or?

    regards
    Martin

    ICI-MASA Guest

  5. #4

    Default Re: Order By or sorting nested querys

    Perhaps...

    <cfquery name="rsUsers" datasource="cf_db">
    SELECT tu.UID, tu.UfirstName, tu.UlastName
    FROM tbUsers tu INNER JOIN tbRights tr ON tu.UID = tr.UID
    WHERE tr.PID = #URL.PID#
    </cfquery>

    <cfoutput query="rsUsers">#UfirstName# &nbsp UlastName#</cfoutput

    paross1 Guest

  6. #5

    Default Re: Order By or sorting nested querys

    Thanks Paross,

    that was the way to go...

    regards
    Martin
    ICI-MASA Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139