SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)

    Complex Access Query

    First of all I'd like to thank those who have helped me through the last week of questions regarding access. I greatly appreciate it. Here is one of my last hurtles for this project.

    The following query works great. 1 employee will have many assignments, 1 assignment to 1 record on tbl12. Now I'd like to also add in to this a table of comments. 1 record on table 142 may have many comments. I cannnot for the life of me add in the comments table so that it does not remove records from the query if a record does not have any comments. I get errors trying to switch it to a left / right join.

    Code:
     SELECT tbl142Assignments.*, tbl142.*, tblEmployees.*, tblEmployees.ID
    FROM tbl142 INNER JOIN (tbl142Assignments INNER JOIN tblEmployees ON tbl142Assignments.assignedTo = tblEmployees.ID) ON tbl142.ID = tbl142Assignments.ID
    WHERE (((tblEmployees.ID)=Environ()));

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    I get errors trying to switch it to a left / right join.
    What errors?
    And can you post the query with the LEFT JOIN that is giving you errors?

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Join Expression not supported is usually what I get. I've tried all kinds of different setups but am having trouble since access doesnt allow outter joins. In any case, I realize I have inner joins set up now but all should be left / right joins.

    Code:
    SELECT tbl142Assignments.*, tbl142.*, tblEmployees.*, tblEmployees.ID
    FROM tbl142 LEFT JOIN (tbl142Assignments LEFT JOIN tblEmployees ON tbl142Assignments.assignedTo = tblEmployees.ID) ON tbl142.ID = tbl142Assignments.ID
    WHERE (((tblEmployees.ID)=Environ()));
    That works the way I want it to also but everything I have so far is 1 to 1 relationship really.. While the comments will have 0 to many

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    of course access allows outer joins!!!

    rewrite your FROM clause as follows:
    Code:
    SELECT something
         , anything
         , just_not_the_dreaded_evil_select_star
      FROM ((
           tblEmployees 
    INNER 
      JOIN tbl142Assignments 
        ON tbl142Assignments.assignedTo = tblEmployees.ID 
           )
    INNER 
      JOIN tbl142 
        ON tbl142.ID = tbl142Assignments.ID
           )
    LEFT OUTER
      JOIN tblComments
        ON tblComments.tbl142ID = tbl142.ID
     WHERE tblEmployees.ID = Environ()
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Excellent. Thank you.

    ps. * was just for readability and privicy :-)

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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