Help with Complex joins

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Gillis

    #1

    Help with Complex joins

    I need some help. Here is the problem.

    Table_1 (gl_Train_KeyId eas)

    +----------------------+----------------+-------------------+---------------+
    | KeyIdea_ID | Unit_ID | Group_ID | Title |
    +----------------------+----------------+-------------------+---------------+
    | 1 | 1 | 27 | yada 1 |
    | | | | |
    | 2 | 1 | 27 | yada 2 |
    | | | | |
    | 3 | 1 | 27 | yada 3 |
    | | | | |
    | 4 | 1 | 27 | yada 4 |
    | | | | |
    +----------------------+----------------+-------------------+----------------+

    Table_2 (gl_Train_Progr ess)

    +----------------------+----------------+----------------------+
    | ID | User_ID | KeyIdea_ID |
    +----------------------+----------------+----------------------+
    | 12 | 5 | 3 |
    | | | |
    | 11 | 5 | 2 |
    | | | |
    | 10 | 5 | 1 |
    | | | |
    +----------------------+----------------+-----------------------+


    The following sql returns field KeyIdea_ID = 4 which is the only
    KeyIdea not in both tables.

    SELECT gl_Train_KeyIde as.KeyIdea_ID
    FROM gl_Train_KeyIde as LEFT JOIN gl_Train_Progre ss ON
    gl_Train_KeyIde as.KeyIdea_ID = gl_Train_Progre ss.KeyIdea_ID
    WHERE (((gl_Train_Pro gress.KeyIdea_I D) Is Null) AND
    ((gl_Train_KeyI deas.Unit_ID)=1 ));

    What I seem to be having trouble with is specifying the User_ID in
    table 2. I need to specify the current user for example: an sql with a
    User_ID = 6 would return KeyIdea_ID of 1, 2, 3, and 4.

    Any idea's?

  • Greg Gillis

    #2
    Re: Help with Complex joins

    I figured it out.

    I used the following sql

    SELECT gl_Train_KeyIde as.KeyIdea_ID
    FROM gl_Train_KeyIde as
    LEFT JOIN gl_Train_Progre ss
    ON gl_Train_KeyIde as.KeyIdea_ID = gl_Train_Progre ss.KeyIdea_ID
    AND gl_Train_Progre ss.User_ID = 6
    WHERE (((gl_Train_Pro gress.KeyIdea_I D) Is Null) AND
    ((gl_Train_KeyI deas.Unit_ID)=1 ));





    On Mon, 05 Apr 2004 18:35:35 GMT, ms150@rcsys.net (Greg Gillis) wrote:
    [color=blue]
    >I need some help. Here is the problem.
    >
    >Table_1 (gl_Train_KeyId eas)
    >
    >+----------------------+----------------+-------------------+---------------+
    >| KeyIdea_ID | Unit_ID | Group_ID | Title |
    >+----------------------+----------------+-------------------+---------------+
    >| 1 | 1 | 27 | yada 1 |
    >| | | | |
    >| 2 | 1 | 27 | yada 2 |
    >| | | | |
    >| 3 | 1 | 27 | yada 3 |
    >| | | | |
    >| 4 | 1 | 27 | yada 4 |
    >| | | | |
    >+----------------------+----------------+-------------------+----------------+
    >
    >Table_2 (gl_Train_Progr ess)
    >
    >+----------------------+----------------+----------------------+
    >| ID | User_ID | KeyIdea_ID |
    >+----------------------+----------------+----------------------+
    >| 12 | 5 | 3 |
    >| | | |
    >| 11 | 5 | 2 |
    >| | | |
    >| 10 | 5 | 1 |
    >| | | |
    >+----------------------+----------------+-----------------------+
    >
    >
    >The following sql returns field KeyIdea_ID = 4 which is the only
    >KeyIdea not in both tables.
    >
    >SELECT gl_Train_KeyIde as.KeyIdea_ID
    >FROM gl_Train_KeyIde as LEFT JOIN gl_Train_Progre ss ON
    >gl_Train_KeyId eas.KeyIdea_ID = gl_Train_Progre ss.KeyIdea_ID
    >WHERE (((gl_Train_Pro gress.KeyIdea_I D) Is Null) AND
    >((gl_Train_Key Ideas.Unit_ID)= 1));
    >
    >What I seem to be having trouble with is specifying the User_ID in
    >table 2. I need to specify the current user for example: an sql with a
    >User_ID = 6 would return KeyIdea_ID of 1, 2, 3, and 4.
    >
    >Any idea's?[/color]

    Comment

    • Greg Gillis

      #3
      Re: Help with Complex joins

      I figured it out.

      I used the following sql

      SELECT gl_Train_KeyIde as.KeyIdea_ID
      FROM gl_Train_KeyIde as
      LEFT JOIN gl_Train_Progre ss
      ON gl_Train_KeyIde as.KeyIdea_ID = gl_Train_Progre ss.KeyIdea_ID
      AND gl_Train_Progre ss.User_ID = 6
      WHERE (((gl_Train_Pro gress.KeyIdea_I D) Is Null) AND
      ((gl_Train_KeyI deas.Unit_ID)=1 ));





      On Mon, 05 Apr 2004 18:35:35 GMT, ms150@rcsys.net (Greg Gillis) wrote:
      [color=blue]
      >I need some help. Here is the problem.
      >
      >Table_1 (gl_Train_KeyId eas)
      >
      >+----------------------+----------------+-------------------+---------------+
      >| KeyIdea_ID | Unit_ID | Group_ID | Title |
      >+----------------------+----------------+-------------------+---------------+
      >| 1 | 1 | 27 | yada 1 |
      >| | | | |
      >| 2 | 1 | 27 | yada 2 |
      >| | | | |
      >| 3 | 1 | 27 | yada 3 |
      >| | | | |
      >| 4 | 1 | 27 | yada 4 |
      >| | | | |
      >+----------------------+----------------+-------------------+----------------+
      >
      >Table_2 (gl_Train_Progr ess)
      >
      >+----------------------+----------------+----------------------+
      >| ID | User_ID | KeyIdea_ID |
      >+----------------------+----------------+----------------------+
      >| 12 | 5 | 3 |
      >| | | |
      >| 11 | 5 | 2 |
      >| | | |
      >| 10 | 5 | 1 |
      >| | | |
      >+----------------------+----------------+-----------------------+
      >
      >
      >The following sql returns field KeyIdea_ID = 4 which is the only
      >KeyIdea not in both tables.
      >
      >SELECT gl_Train_KeyIde as.KeyIdea_ID
      >FROM gl_Train_KeyIde as LEFT JOIN gl_Train_Progre ss ON
      >gl_Train_KeyId eas.KeyIdea_ID = gl_Train_Progre ss.KeyIdea_ID
      >WHERE (((gl_Train_Pro gress.KeyIdea_I D) Is Null) AND
      >((gl_Train_Key Ideas.Unit_ID)= 1));
      >
      >What I seem to be having trouble with is specifying the User_ID in
      >table 2. I need to specify the current user for example: an sql with a
      >User_ID = 6 would return KeyIdea_ID of 1, 2, 3, and 4.
      >
      >Any idea's?[/color]

      Comment

      Working...