I have two tables, users and hra. A user can only have one record in users table, but he can have multiple hras. What I want to do is only retrieve one hra per user. I have the query below. Anyone can help to do that?
$query = "SELECT u.id AS user_id, h.id AS hra_id FROM users u
INNER JOIN hra h ON u.id = h.user_id
WHERE h.date BETWEEN ? AND ?
AND h.done = 1
Assuming you want the MAX(h.id), this should work: