We help IT Professionals succeed at work.

SQL Help

190 Views
Last Modified: 2010-03-20
Hello experts.

I have 3 tables

tbl_UserProfile
UserId

tbl_Roles
RoleId      RoleName
1              user
2              power user
3              admin

tbl_UsersInRoles
UserId     RoleId

Basically I am using ASP.NET to display all users only in the "user" and "power user" Role

I have attempted it but im not very good at SQL. Can anyone help?
SELECT 
tbl_UserProfile.UserFirstName, 
tbl_UserProfile.UserLastname, 
tbl_UserProfile.UserProfileId, 
tbl_UserProfile.UserId, 
aspnet_Roles.RoleId, 
aspnet_UsersInRoles.RoleId, 
aspnet_UsersInRoles.UserId 
 
FROM 
tbl_UserProfile, 
aspnet_Roles, 
aspnet_UsersInRoles, 
 
WHERE 
tbl_UserProfile.UserId = aspnet_UsersInRoles.UserId 
AND aspnet_Roles.RoleName = 'user'
AND aspnet_Roles.RoleName = 'power user'

Open in new window

Comment
Watch Question

Applications and Integrations Consultan
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Awarded 2008
Awarded 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
A modification to your query in your way, try this
SELECT 
tbl_UserProfile.UserFirstName, 
tbl_UserProfile.UserLastname, 
tbl_UserProfile.UserProfileId, 
tbl_UserProfile.UserId, 
aspnet_Roles.RoleId, 
aspnet_UsersInRoles.RoleId, 
aspnet_UsersInRoles.UserId 
 
FROM 
tbl_UserProfile, 
aspnet_Roles, 
aspnet_UsersInRoles, 
 
WHERE 
tbl_UserProfile.UserId = aspnet_UsersInRoles.UserId 
AND aspnet_UsersInRoles.UserID=aspnet_UsersInRoles.UserId 
AND aspnet_Roles.RoleName IN ('user', 'power user')

Open in new window

Author

Commented:
Tim and chapmandew: you are close to an answer.

The only problem with the queries is that it shows each admin twice.

Author

Commented:
my bad, the users that were showing twice were in all 3 roles.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.