繁体   English   中英

使用条件左联接

[英]Left join using a condition

我有这个问题。

我需要从匹配表中获取以下字段:

date, points

然后我的匹配表中也有一个epos_id字段。

我还有另一个具有epos_idlocation字段的rbpos_epos表。

我需要使用连接从rbpos_epos获取location

SELECT matching.date, matching.points, matching.time,matching.location,matching.epos_id,rbpos_epos.epos_id,rbpos_epos.location
FROM matching  WHERE matching.user_id="'.$id_user.'"
LEFT JOIN rbpos_epos where matching.epos_id=rbpos_epos.epos_id; 

在以下位置使用-

    SELECT matching.date, matching.points, matching.time,matching.location,matching.epos_id,rbpos_epos.epos_id,rbpos_epos.location
   FROM matching LEFT JOIN rbpos_epos ON matching.epos_id=rbpos_epos.epos_id      
      WHERE matching.user_id="'.$id_user.'";

尝试这个:

SELECT m.date, m.points, m.time,m.location,m.epos_id,re.epos_id,re.location
FROM matching  m 
LEFT JOIN rbpos_epos re ON m.epos_id=re.epos_id
WHERE m.user_id= 10
SELECT 
    first_table.date,
    first_table.points,
    first_table.time,
    first_table.location,
    first_table.epos_id,
    rbpos_epos.epos_id,
    rbpos_epos.location
FROM
    first_table
LEFT JOIN
    rbpos_epos ON first_table.epos_id = rbpos_epos.epos_id
WHERE
    first_table.user_id = "'.$id_user.'";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM