0

这是我想要实现的一个非常简化的示例:

USERS
 id      |    name          
 12      |    Phil      

ACTIONS
 sender  |  recipient
 12      |  Alice

$table = query("SELECT id, sender FROM users WHERE recipient = Alice");
foreach ($table as $row) {
$sender = $row['sender'];

echo '$sender has sent a gift to Alice';
}

这将输出:

12 sent a gift to Alice

我怎样才能得到下面的输出呢?

**Phil** sent a gift to Alice

我应该加入这两个表吗?

4

1 回答 1

1

您需要加入:

SELECT u.name, sender
FROM actions a join
     users u
     on a.sender = u.id
WHERE recipient = 'Alice';
于 2013-08-25T01:30:26.587 回答