我想使用另一个表tbl_users和一个列mergeing的值从一个名为donator_1的表中选择数据。

我尝试了以下方法:

$result = $DBcon->query("SELECT tbl_users.username, tbl_users.email, tbl_users.Phone_number FROM tbl_users,mergeing WHERE mergeing.donator_1= tbl_users.user_id AND mergeing._id = 6");
while($row = $result->fetch_array()) {
  echo '<b>' . $l['user_id'] .'</b><b>' . $l['username'] . '</b>';
}

最佳答案

您可以尝试嵌套查询:

SELECT username, email, Phone_number
FROM tbl_users
WHERE user_id = (SELECT donator_1 FROM mergeing WHERE _id = 6 )


或内部联接:

SELECT username, email, Phone_number
FROM tbl_users
JOIN mergeing ON tbl_users.user_id = mergeing.donator_1
WHERE mergeing._id = 6

关于php - 如何使用另一个表中的值从一个表中选择数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42749338/

10-11 23:55