使用条件进行左连接

时间:2013-01-04 11:01:22

标签: mysql select join left-join

我有这个问题。

我需要从匹配表中获取这些字段:

date, points

然后我在匹配表中也有一个epos_id字段..

我有另一个rbpos_epos表,其中包含epos_idlocation字段。

我需要使用连接从location获取rbpos_epos ..这样的事情:

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; 

3 个答案:

答案 0 :(得分:0)

使用而不是 -

    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.'";

答案 1 :(得分:0)

试试这个:

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

答案 2 :(得分:0)

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.'";