Multiple Joins in one Query for CFGRID

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

  1. #1

    Default Multiple Joins in one Query for CFGRID

    Hello,

    I am tring to combine all 4 queries into 1 so that it will work in a CFGRID
    and it's a little beyond my SQL experience. I have all this working (see code
    below) and decided that using the CFGRID would allow and Excel user to be able
    to edit the records easier.

    I have a table of User's IDs.

    student_id, senior_advisor_id, faculty_advisor_id, osa_advisor_id, etc..

    Based on those IDs, I need to be able to grab each user's information (ie, get
    the student name from one table and their email address from another table. The
    same goes for the senior advisor, faculty advisor and osa advisor.) How do I do
    this?

    <cfquery datasource="#session.dsn#" name="qSelectAdvisorMentor">
    select u.user_type_id, ui.edcom_id, ui.firstname, ui.lastname, ui.email, am.*
    from users u, user_info ui, advisor_mentor am
    where u.edcom_id = ui.edcom_id
    and ui.edcom_id = am.student_edcom
    and u.user_type_id IN (1101, 1111)
    order by u.user_type_id ASC, ui.lastname asc, ui.firstname asc
    </cfquery>

    <table border="1" cellpadding="4" cellspacing="0" width="100%">
    <tr>
    <th>Report</th>
    <th>Student</th>
    <th>Senior Mentor</th>
    <th>Faculty Mentor</th>
    <th>OSA Advisor</th>
    <th>Big Sib</th>
    <th>Senior Faculty Advisor</th>
    </tr>
    <cfoutput query="qSelectAdvisorMentor">
    <cfquery datasource="#session.dsn#" name="qSelectSeniorMentorInfo">
    select ui.edcom_id, ui.firstname, ui.lastname, ui.email
    from users u, user_info ui
    where u.edcom_id = ui.edcom_id
    and u.edcom_id = <cfqueryparam
    value="#qSelectAdvisorMentor.senior_mentor_edcom#" cfsqltype="CF_SQL_VARCHAR">
    </cfquery>
    <cfquery datasource="#session.dsn#" name="qSelectFacultyMentorInfo">
    select ui.edcom_id, ui.firstname, ui.lastname, ui.email
    from users u, user_info ui
    where u.edcom_id = ui.edcom_id
    and u.edcom_id = <cfqueryparam
    value="#qSelectAdvisorMentor.faculty_mentor_edcom# " cfsqltype="CF_SQL_VARCHAR">
    </cfquery>
    <cfquery datasource="#session.dsn#" name="qSelectOSAAdvisorInfo">
    select ui.edcom_id, ui.firstname, ui.lastname, ui.email
    from users u, user_info ui
    where u.edcom_id = ui.edcom_id
    and u.edcom_id = <cfqueryparam
    value="#qSelectAdvisorMentor.osa_advisor_edcom#" cfsqltype="CF_SQL_VARCHAR">
    </cfquery>
    <tr bgcolor=###iif(qSelectAdvisorMentor.currentrow mod 2, de ('eeeeee'), de
    ('d4d4d4'))#>
    <td align="center"><a href="report.cfm?id=#qSelectAdvisorMentor.edcom_id #"
    target="_blank">Report View</a></td>
    <td>&nbsp;<a
    href="mailto:#qSelectAdvisorMentor.email#">#qSelec tAdvisorMentor.lastname#,
    #qSelectAdvisorMentor.firstname#</a></td>
    <td><cfif qSelectSeniorMentorInfo.edcom_id NEQ ""><!---
    #qSelectSeniorMentorInfo.edcom_id# ---><a
    href="mailto:#qSelectSeniorMentorInfo.email#">#qSe lectSeniorMentorInfo.lastname#
    , #qSelectSeniorMentorInfo.firstname#</a><cfelse>&nbsp;</cfif></td>
    <td><cfif qSelectFacultyMentorInfo.edcom_id NEQ ""><!---
    #qSelectFacultyMentorInfo.edcom_id# ---><a
    href="mailto:#qSelectFacultyMentorInfo.email#">#qS electFacultyMentorInfo.lastnam
    e#, #qSelectFacultyMentorInfo.firstname#</a><cfelse>&nbsp;</cfif></td>
    <td><cfif qSelectOSAAdvisorInfo.edcom_id NEQ ""><!---
    #qSelectOSAAdvisorInfo.edcom_id# ---><a
    href="mailto:#qSelectOSAAdvisorInfo.email#">#qSele ctOSAAdvisorInfo.lastname#,
    #qSelectOSAAdvisorInfo.firstname#</a><cfelse>&nbsp;</cfif></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </cfoutput>
    </table>


    I'd really appreciate the help.

    Thanks

    Josh


    jbreslow Guest

  2. Similar Questions and Discussions

    1. Deletion based on the result of a 3 table right joins select query (MySQL 3.23)
      I am using MySQL 3.23 I have a relatively complex database with a number of Many to Many relationships (using link tables). I want to delete...
    2. Query problem - multiple left joins??
      I have an employee table, and an organization table. The employee table contains an ouID link which always has a match in the org.table. The...
    3. multiple inner joins
      Hi, im a newbi to coldfusion and i need to multiple inner joins between tables in a database - some one has give me the sql version(from an old...
    4. Syntax for ambigous fields in a query with joins?
      Hello, I run a select query in PHP using 1 table joined to 3 other tables. All well and good, but there are fields in these tables that have...
    5. Help on Multiple JOINS
      Paul Eaton wrote: Yes, unless it's Access, which is really picky about using parentheses to group the joins. If you're using Access, use the...
  3. #2

    Default Re: Multiple Joins in one Query for CFGRID

    Can you briefly state the names of the tables involved and the relationships between them (ie. Primary Keys/Foreign Keys)?
    mxstu 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