所以,我在这里有这个查询:
$query1 = 'SELECT users.first_name,users.last_name,users.phone, matching.date, matching.points, matching.time, matching.epos_id,rbpos_epos.epos_id,rbpos_epos.location
FROM users LEFT JOIN matching WHERE users.user_id="'.$id_user.'"
AND users.user_id=matching.user_id
LEFT JOIN rbpos_epos WHERE rbpos_epos.epos_id=matching.epos_id';
这给了我一个错误,我在最后一行中试图做的是:
LEFT JOIN rbpos_epos WHERE rbpos_epos.epos_id=matching.epos_id';
是获取特定 epos_id 的位置。
这意味着,在匹配表中,我有一个 epos_id 列,在 rbpos_epos 列中,我有一个 epos_id 字段,旁边有一个位置字段。我需要为每个 epos_id 获取各自的位置。
我做错了什么? 谢谢..
这个有效
$query1 = 'SELECT users.first_name,users.last_name,users.phone, matching.date, matching.points, matching.time,matching.location
FROM users ,matching WHERE users.user_id="'.$id_user.'"
AND users.user_id=matching.user_id';
我需要从 rbpos_epos 表中获取位置。 rbpos_epos和matching这两个表都有一个epos_id字段
所以我需要的是根据匹配时的 epos_id 在 rbpos_epos 中找到位置..
最佳答案
试试这个::
SELECT users.first_name,users.last_name,users.phone, matching.date, matching.points, matching.time, matching.epos_id,rbpos_epos.epos_id,rbpos_epos.location
FROM users
INNER JOIN matching ON users.user_id=matching.user_id
INNER JOIN rbpos_epos ON rbpos_epos.epos_id=matching.epos_id
WHERE users.user_id="'.$id_user.'"
关于php - 查询中的多个左连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14153731/