来自两张表的PHP MYSQL查询记录

问题描述

请问我是不熟悉PHP / MysqL我有两张桌子。餐桌员工有(id,全名),餐桌员工有(id,staff_id)。 我打算进行查询获取在出勤表中所有没有id为staff_id的职员。下面是我的PDO代码

$att = $con->prepare('SELECT member_id FROM attendance');
$att->execute();
while ($att_fetch = $att->fetch()) {
$absent = $con->prepare('SELECT * FROM members WHERE id != "'.$att_fetch['member_id'].'" ');
$absent->execute();
$absent_fetch = $absent->fetch();
echo '
  <tr>
   <td class="name" data-id="'.$absent_fetch['id'].'">'.ucwords($absent_fetch['fullname']).'</td>
  </tr> 
';
}

令人惊讶的是,这将返回出席表中的所有职员。 请帮帮我

解决方法

我打算进行查询,以获取test_data <- data.frame(x = 1:3,y = 1:3) 表中没有id作为staff_id的所有员工。

您不需要两个查询以及一些PHP逻辑。您可以使用attendance在单个查询中获得所需的结果:

not exists