Results 1 to 6 of 6
  1. #1
    zephaneas is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2008
    Posts
    15

    Help Understanding Join Syntax In Access

    I don't undersand the JOIN syntaxin Access. Assuming this query:

    http://www.maroisconsulting.com/temp/query.png

    MS Sql does it with one join per line. How does Access come up with this strange nesting of JOINs? Can someone explain.

    Code:
     
    SELECT Count(Employees.EmployeeId) AS Total
    FROM (((Employees INNER JOIN Titles ON Employees.TitleId = 
    Titles.TitleId) INNER JOIN EmployeeStores ON Employees.EmployeeId = 
    EmployeeStores.EmployeeId) INNER JOIN Stores ON 
    EmployeeStores.StoreId = Stores.StoreId) INNER JOIN Groups ON 
    Stores.GroupId = Groups.GroupId
    Thanks

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    The syntax itself for MS SQL should be the same. Are you confusing that it's just on different lines? Or are you comparing a vba sql statement to a MS SQL cursor or trigger versus a view?

  3. #3
    zephaneas is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2008
    Posts
    15
    It's not the same at all in MS SQL.

    In SQL you don't have nested Joins. I can't figure out how the designer comes up with it.

  4. #4
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Again, are you referring to a VIEW in SQL Server or a CURSOR, STORED PROCEDURE or TRIGGER?

    (I'm assuming MS SQL is also referring to SQL Server.)

    It's been a while since I've designed a view, cursor, stored procedure or trigger in SQL Server. You're probably right on nested queries but the join type syntax should be the same.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I think this syntax is valid (untested)
    SELECT Count(Employees.EmployeeId) AS Total
    FROM
    Employees
    ,EmployeeStores
    ,Stores
    ,Groups
    WHERE
    Employees.TitleId = Titles.TitleId and
    Employees.EmployeeId = EmployeeStores.EmployeeId and
    EmployeeStores.StoreId = Stores.StoreId and
    Stores.GroupId = Groups.GroupId

  6. #6
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    This:
    SELECT Count(Employees.EmployeeId) AS Total
    FROM
    Employees
    ,EmployeeStores
    ,Stores
    ,Groups
    WHERE
    Employees.TitleId = Titles.TitleId and
    Employees.EmployeeId = EmployeeStores.EmployeeId and
    EmployeeStores.StoreId = Stores.StoreId and
    Stores.GroupId = Groups.GroupId

    is the same as this:
    SELECT Count(Employees.EmployeeId) AS Total FROM Employees ,EmployeeStores ,Stores, Groups WHERE Employees.TitleId = Titles.TitleId and Employees.EmployeeId = EmployeeStores.EmployeeId and EmployeeStores.StoreId = Stores.StoreId and Stores.GroupId = Groups.GroupId

    but this (from your 1st post):
    SELECT Count(Employees.EmployeeId) AS Total
    FROM (((Employees INNER JOIN Titles ON Employees.TitleId =
    Titles.TitleId) INNER JOIN EmployeeStores ON Employees.EmployeeId =
    EmployeeStores.EmployeeId) INNER JOIN Stores ON
    EmployeeStores.StoreId = Stores.StoreId) INNER JOIN Groups ON
    Stores.GroupId = Groups.GroupId

    is using an INNER JOIN (ie. all records from one table and only matching records from the joined table.) If you copy and paste the 1st syntax above into the query SQL, then switch to the graphical designer mode and compare that to the last syntax pasted into a query SQL and look at the graphical designer mode, I 'think' you'll notice a difference in how the joins are put together (ie. the arrow on the join for the tables will be different.)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-20-2013, 08:36 AM
  2. Replies: 2
    Last Post: 06-13-2011, 06:04 PM
  3. Understanding afterupdate
    By MAM8433 in forum Access
    Replies: 8
    Last Post: 05-23-2011, 02:05 PM
  4. Not understanding Running Sum Query
    By dynamictiger in forum Queries
    Replies: 4
    Last Post: 08-30-2010, 11:50 AM
  5. Understanding SQL Querys
    By jacobbiljo in forum Access
    Replies: 8
    Last Post: 11-17-2009, 05:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums