开发者

Why Doesn't This MySQL Query Return More Results?

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.EntryI开发者_运维百科D = 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.


Slightly re-structured...

SELECT DISTINCT STRAIGHT_JOIN 
      e1.ID,
      rf.Email 
   FROM
      Entries e1
         JOIN ReferAFriend rf
            on e1.ID = rf.EntryID
            JOIN Entries e2
               on rf.EMail = e2.EMail
   where
      e1.ID = 47667

Can you query and show the results of...

SELECT DISTINCT 
      e1.ID,
      rf.Email 
   FROM
      Entries e1
         JOIN ReferAFriend rf
            on e1.ID = rf.EntryID
   where
      e1.ID = 47667


The WHERE clause is filtering out the results to just one. Changed that and it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜