我有两个看起来像这样的表(作为示例):
表销售:
| ID | date | displayname | status |
| 1 | 2020/08/03 16:25:26 | Angel | OK |
| 2 | 2020/08/03 16:25:26 | Angel | OK |
| 3 | 2020/08/03 16:25:26 | Cabil | X |
| 4 | 2020/08/03 16:25:26 | Syed | OK |
...
表用户(所有列均具有值,但出于GDPR的原因而被删除):
| ID | displayname | fullname | email |
| 1 | Angel | | |
| 2 | Nico | | |
| 3 | Raquie | | |
| 4 | Cabil | | |
| 5 | Syed | | |
...
我有一个如下所示的PHP脚本:
<?php
$query = "SELECT * FROM sales WHERE status='OK' ORDER BY STR_TO_DATE(`date`, '%Y/%m/%d %H:%i:%s') DESC LIMIT 5";
if ($result = $link->query($query)) {
$num_rows = 0;
while ($row = $result->fetch_assoc()) {
$num_rows++;
echo '<div class="my-box">';
echo "{$row['id']}";
echo "{$row['date']}";
echo "{$row['dbirth']}";
echo "{$row['email']}";
echo "{$row['displayname']}";
echo '</div>';
}
$result->free();
}
?>
现在,它当前显示echo "{$row['displayname']}";
中每笔销售的每个显示名称,但是在显示名称的基础上,我想为具有当前显示名称的用户显示全名。我该怎么做?
答案 0 :(得分:0)
您似乎正在寻找联接:
select s.*, u.fullname
from sales s
inner join users u on u.displayname = u.displayname