0

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).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Emad Saeed
  • 106
  • 7

0 Answers0