Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created December 6, 2011 10:57
Show Gist options
  • Select an option

  • Save mikebaldry/1437786 to your computer and use it in GitHub Desktop.

Select an option

Save mikebaldry/1437786 to your computer and use it in GitHub Desktop.
Query optimisation..
SELECT c.contract_id, csc1.changed_status
FROM contract c
LEFT
JOIN contract_status_change csc1
ON csc1.contract_status_change_id =
( SELECT csc2.contract_status_change_id
FROM contract_status_change csc2
WHERE csc2.contract_id = c.contract_id
ORDER
BY csc2.date_changed DESC
LIMIT 1
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment