0

我在这里有这个查询:

$query_pag_data = "SELECT 
matching.date,
matching.points,
matching.time,
matching.location,
matching.epos_id,
matching.rbpos_id,
matching.time_added,
rbpos_epos.epos_id,
rbpos_epos.rbpos_id,
rbpos_epos.location
FROM
matching
LEFT JOIN
rbpos_epos ON matching.epos_id = rbpos_epos.epos_id AND
matching.rbpos_id = rbpos_epos.rbpos_id WHERE
matching.user_id = ".$id_user." ORDER BY matching.time_added DESC LIMIT ".$start.", ".$per_page;

所以,问题是,我在这部分有问题:

 rbpos_epos ON matching.epos_id = rbpos_epos.epos_id AND matching.rbpos_id = rbpos_epos.rbpos_id

它不起作用,没有错误或任何东西,但它不会给出预期的结果。

match.epos_id /rbpos_id 都是 varchar 类型。有什么建议吗?谢谢

IE

Matching column
ID  rbpos_id    epos_id
1   123         1234

Rbpos_epos
ID   rbpos_id    epos_id
1    123         1234
2    12          12

我应该得到第一行......因为那是matching.rbpos_id和matching.epos_id等于rbpos_epos.rbpos_id和rbpos_epos.epos_id的地方

回声

SELECT matching.date, matching.points, matching.time, matching.location, matching.epos_id, matching.rbpos_id, matching.time_added, rbpos_epos.epos_id, rbpos_epos.rbpos_id, rbpos_epos.location FROM matching LEFT JOIN rbpos_epos ON matching.epos_id = rbpos_epos.epos_id AND matching.rbpos_id = rbpos_epos.rbpos_id WHERE matching.user_id = 4171446415 ORDER BY matching.time_added DESC LIMIT 0, 5
4

2 回答 2

0

如果您只想检索matching其中具有匹配行的行,rbpos_epos您可能应该LEFT JOIN只替换为JOIN(或INNER JOIN)。

于 2013-06-18T17:02:55.260 回答
0

为什么不在一个条件下加入并在 where 条件下过滤数据:-

$query_pag_data = "SELECT 
  m.date,
  m.points,
  m.time,
  m.location,
  m.epos_id,
  m.rbpos_id,
  m.time_added,
  r.epos_id,
  r.rbpos_id,
  r.location
  FROM
  matching as m
  LEFT JOIN
  rbpos_epos as r ON m.epos_id = r.epos_id WHERE
  m.rbpos_id = r.rbpos_id AND
  m.user_id = ".$id_user." ORDER BY m.time_added DESC LIMIT ".$start.", ".$per_page;
于 2013-06-18T12:23:35.667 回答