Reputation: 5162
I am trying to join data from two tables where the userid from table 1 is in table 2. I have tried multiple variations with no luck and read a dozen posts here on SO on this topic.
The data in table one has an id, username, rolerequest, and appuserid. I am selecting the last three items and trying to join 3 items from table 2 when the appserid from table 1 is equal to the userid from table 2.
here is my latest attempt;
SELECT username, rolerequest, appuserid
FROM userrolespending
LEFT JOIN my_aspnet_membership.email,my_aspnet_membership.creationdate,my_aspnet_membership.lastlogindate
where my_aspnet_membership.userid = userrolespending.appuserid;
Upvotes: 1
Views: 77
Reputation: 263693
In this case, you don't need to use LEFT JOIN
because you only want to return userid
that are present from both tables. INNER JOIN
returns records that the ID
or the linking columns are both present on all tables.
SELECT a.*, b.* -- <== select the columns you want to appear
FROM userrolespending a
INNER JOIN my_aspnet_membership b
ON a.appserid = b.userID
or to be exact,
SELECT a.username, a.rolerequest, a.appuserid,
b.email,b.creationdate, b.lastlogindate
FROM userrolespending a
INNER JOIN my_aspnet_membership b
ON a.appserid = b.userID
Upvotes: 1
Reputation: 1716
i think this is what you need :
SELECT username, rolerequest, appuserid
FROM userrolespending
LEFT JOIN my_aspnet_membership
on my_aspnet_membership.userid = userrolespending.appuserid;
Upvotes: 0