我有一个获取搜索结果的查询,效果很好。
查询成功示例:
SELECT
individuals.individual_id,
individuals.unique_id,
TIMESTAMPDIFF(YEAR,individuals.day_of_birth,CURDATE()) AS age,
individuals_dynamics.id,
individuals_achievements.degree
FROM
individuals as individuals
LEFT JOIN
individuals_dynamics AS individuals_dynamics ON individuals.unique_id = individuals_dynamics.individual_id
LEFT JOIN
individuals_achievements AS individuals_achievements ON individuals.unique_id = individuals_achievements.individual_id
WHERE
$uuid_access_status $display_type $detailed_search_query
ORDER BY
$search_sort $search_order
从现在开始,我每个人都有不止一个记录,individuals_achievements
这是我想获得 MAX 值(最新 id)的地方。
我尝试了许多不同的查询,但总是收到错误调用非对象上的成员函数 rowCount()。
我理解这个错误的含义,但我不知道我在哪里犯了这个错误,以及一般是什么错误。
我不成功的尝试示例:
SELECT
individuals.individual_id,
individuals.unique_id,
TIMESTAMPDIFF(YEAR,individuals.day_of_birth,CURDATE()) AS age,
individuals_dynamics.id,
individuals_achievements.degree
FROM
individuals as individuals
LEFT JOIN
individuals_dynamics AS individuals_dynamics ON individuals.unique_id = individuals_dynamics.individual_id
INNER JOIN
(
SELECT
degree, MAX(id) AS latest_record
FROM
individuals_achievements
GROUP BY
latest_record
) individuals_achievements AS individuals_achievements ON individuals.unique_id = individuals_achievements.individual_id
WHERE
$uuid_access_status $display_type $detailed_search_query
ORDER BY
$search_sort $search_order
我在这里想念什么?请问有什么帮助吗?