0

我在这里有这个查询:

$query_pag_data = "SELECT 
matching.date,
matching.points,
matching.time,
matching.location,
matching.epos_id,
matching.time_added,
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." LIMIT $start, $per_page ORDER BY matching.time_added DESC";

我在 ORDER BY 部分收到错误,出了什么问题,我应该把它放在哪里?...

4

2 回答 2

1

您已经交换了 ORDER BY 和 LIMIT 子句的顺序。首先是 ORDER BY 子句,然后是 LIMIT 子句。这应该有效:

$query_pag_data = "SELECT 
matching.date,
matching.points,
matching.time,
matching.location,
matching.epos_id,
matching.time_added,
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." ORDER BY matching.time_added DESC LIMIT ".$start.", ".$per_page;
于 2013-06-08T07:35:38.680 回答
0

限制总是在结果收集结束时应用,因此在 order by 之后。

鉴于您的所有条款,处理顺序将是

  • 在哪里
  • 选择
  • 订购方式
  • 限制

因此,您将获得与 WHERE 子句中的所有条件匹配的最接近的记录 <= publishedOn。

@信用:RichardTheKiwi

于 2013-06-08T07:34:42.947 回答