April 22, 2014 at 1:15 pm
I have 3 Tables; User, UserType, Permissions -
Common Field between User and UserType is UserTypeID
Common Field between UserType and Permissions is PermID
In the User Table, I also have a field for UserID.
Now I perform a query to pull a UserID based on Username/pw entered by user.
What would be the most efficient SELECT/JOIN statement to JOIN the 3 tables and pull the PermID?
thanks
Frank
April 22, 2014 at 1:34 pm
Inner Join is the fastest way, if you are referring to a single user at any time.. see below code
SELECT c.PermID
FROM Users a
INNER JOIN UserType b ON a.UserID = b.UserID
INNER JOIN UserPermissions c ON c.PermID = b.PermID
WHERE a.UserID = @user-id
Good Luck 🙂 .. Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
April 22, 2014 at 1:34 pm
How are we supposed to know?
You didn't bother to mention where the columns you're referring to (Username/pw) are stored.
So my guess is: You don't need to join any tables at all. Just query the one that has all columns you're looking for.
If you prefer a more qualified answer, please provide more qualified information.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply