May 17, 2023
4
Level 1
group by but latest record
I have 4 record with same column name and same value. so I do group by that column name but i want Latest record as per created date desc on that groupby my query is
SELECT * FROM tbl_ear_score WHERE `user_id`='".$_REQUEST['user_id']."' AND chapter_id='".$_REQUEST['chapter_id']."' AND best_time != 0 GROUP BY level, type
In this query give me 1st record of that group by but I want latest record as per created date
Level 11
try
SELECT *
FROM tbl_ear_score
WHERE `user_id` = '".$_REQUEST['user_id']."'
AND chapter_id = '".$_REQUEST['chapter_id']."'
AND best_time != 0
AND (level, type, created_date) IN (
SELECT level, type, MAX(created_date)
FROM tbl_ear_score
WHERE `user_id` = '".$_REQUEST['user_id']."'
AND chapter_id = '".$_REQUEST['chapter_id']."'
AND best_time != 0
GROUP BY level, type
)
Please or to participate in this conversation.