Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2012
    Posts
    11

    Unanswered: INNER JOIN same Table twice?

    Account
    accountId
    accountName
    accountPassword
    userId

    User
    userId
    userName
    userAddress
    userType

    Staff
    staffId
    staffName
    staffPassword
    userId

    I want to inner join them but it did not produce any results. The results I want to product is the userType. Is that possible in the 1st place?
    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    looks like a user can have one or more accounts, and a user can also have one or more staffs

    what exactly are you trying to retrieve? the usertype of which, account or staff? or all of them?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2012
    Posts
    11
    usertype means to check if the type of user is a staff or an account(registered customer)

    edit:
    is not one or more accounts and one or more staff account
    both are one-to-one relationships.
    So is it possible to make a select statement joining all together?
    I am trying to see which type of account is it when i sign in to the website
    Thanks
    Last edited by unknown80; 06-15-12 at 11:19.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT u.userId
         , u.userName
         , u.userAddress
         , u.userType       
         , a.accountId      
         , a.accountName    
         , a.accountPassword
         , s.staffId          
         , s.staffName       
         , s.staffPassword   
      FROM User AS u
    LEFT OUTER
      JOIN Account AS a
        ON a.userId = u.userId
    LEFT OUTER
      JOIN Staff AS s
        ON s.userId = u.userId
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jun 2012
    Posts
    11
    COOL! IT WORKS! THANK YOU SO MUCH!!! It was just an example but it totally rock-ed!!
    Sorry but I got a few more questions.. :X
    May I know what is left outer join? How to use it?
    And what is the difference between
    "Account a" and "Account As a"?

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by unknown80 View Post
    May I know what is left outer join? How to use it?
    google is your friend


    Quote Originally Posted by unknown80 View Post
    And what is the difference between
    "Account a" and "Account As a"?
    optional AS keyword is optional
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jun 2012
    Posts
    11
    OHHH KKK THANKKKSS ALOTT!!!!

Posting Permissions

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