我想使用另一个名为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>';
}
答案 0 :(得分:1)
您可以尝试嵌套查询:
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