I have two tables (agents
, visits
).
Agents can have many visits each with its timestamp
I want to select all agents using left join
without agent duplicates and if the agent has many visits then show the most recent one i.e select the last timestamp in visits table.
I tried the following query
SELECT *
FROM agents
LEFT
JOIN visits
ON agent_id = visit_id
GROUP
BY agent_id
This works well without agent duplicates but shows the oldest visit and I want to show the last one (the most recent timestamp in the second table visits
).