Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    1

    Unanswered: ANSI-92 inner join vs. where clause syntax

    Having problems rewriting my join condition using the "inner join" syntax.

    My query, working with an intersection table:

    SELECT Description, EmailAddress
    FROM Accounts_Roles r, Accounts_Users u, Accounts_UserRoles ur
    WHERE
    r.RoleID = ur.RoleID
    AND
    u.UserID = ur.UserID

    This works fine, but i want to write it using 'inner join' style, so I tried:

    SELECT Description, EmailAddress
    FROM Accounts_Roles r, Accounts_Users u
    INNER JOIN Accounts_UserRoles ur
    ON
    r.RoleID = ur.RoleID
    AND
    u.UserID = ur.UserID

    which gives me an error (The column prefix 'r' does not match with a table name or alias name used in the query.)

    Any ideas as to how I'm screwing this up would be appreciated.

    Thanks,
    Gordon Z

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use:
    Code:
    SELECT Description, EmailAddress
       FROM Accounts_UserRoles ur 
       INNER JOIN Accounts_Roles r
          ON (r.RoleID = ur.RoleID)
       INNER JOIN Accounts_Users u
          ON (u.UserID = ur.UserID)
    -PatP

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Someone here (at Rackspace) has already come up with a cleche based on talking to me: Take the JOIN out of your WHERE clause (and then adding something like "...and take your head out of your @$$"), which is actually based on what Rudy (come out and play here!!!) would enumerate for you very accurately, but I just say that WHERE is processed after JOIN. So I'll let you come up to your own conclusion
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i really admire people who recognize that there is a difference between JOIN syntax and the older table list method, and are trying to make the change and learn the better way
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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