What I am trying to do is list an entry each time they have referred someone and that person is listed in the entries table as well. 3 different queries I have tried are:
SELECT a.ID,b.Email FROM Entries a
INNER JOIN ReferAFriend b ON b.EntryID = a.ID
INNER JOIN (SELECT DISTINCT Email FROM Entries c ON b.Email = c.Email)
WHERE a.ID = 47667
SELECT a.ID,b.Email FROM Entries a
INNER JOIN ReferAFriend b ON b.EntryID = a.ID AND b.Email IN (SELECT DISTINCT Email FROM Entries)
WHERE a.ID = 47667
SELECT a.ID,b.Email FROM Entries a
INNER JOIN ReferAFriend b ON b.EntryID = a.ID
WHERE b.Email IN (SELECT DISTINCT Email FROM Entries) AND a.ID = 47667
The result of all 3 is just 1 entry.
If I do:
SELECT a.ID,b.Email FROM Entries a
INNER JOIN ReferAFriend b ON b.EntryID = a.ID
WHERE a.ID = 47667
I get a list of 20 entries because there are 20 referred friends, however there are only 4 that are in the entries database, which is what the other query is supposed to filter from these 20, but it only returns 1 result.
Can anyone point me in the right direction here?
Thanks.
The WHERE clause is filtering out the results to just one. Changed that and it works.