I have a localDB database that includes the following tables:
UserProfile, which contains:
UserId UserName
1 Adam
webpages_Roles, which contains:
RoleID RoleName
1 user
2 admin
webpages_UsersInRoles, which has two columns (UserId, RoleId), and is blank.
I want a query to add a user by name into a role by name. to figure out what to insert, if I run:
SELECT UserId, RoleID
FROM UserProfile, webpages_Roles
WHERE UserProfile.UserName = 'Adam'
OR webpages_roles.RoleName = 'admin';
I get this:
UserId RoleId
1 2
1 1
which makes sense; it's a cross join. But I basically just want to run two separate selects at once and stick them together. I tried this:
SELECT UserId, RoleID
FROM UserProfile, webpages_Roles
WHERE UserProfile.UserName = 'Adam'
AND webpages_roles.RoleName = 'admin';
and it worked; I got UserId 1 and RoleId 2. but I don't understand that "and"; isn't it like comparing apples to oranges? shouldn't it be a syntax error? Is localDB actually running two selects and joining the results, perhaps by line number?