Skip to content

Instantly share code, notes, and snippets.

@rafaeljesus
Created January 9, 2015 18:51
Show Gist options
  • Select an option

  • Save rafaeljesus/f782e8b47d35b9eddb64 to your computer and use it in GitHub Desktop.

Select an option

Save rafaeljesus/f782e8b47d35b9eddb64 to your computer and use it in GitHub Desktop.
Over SQL
/*
* repair_notification has_many quotations
* -------------
* | quotation |
* _______________________
* | id | notification_id |
*/
select * from
(select priority, notification_id, row_number() over(partition by notification_id order by quotation_date desc, createddate desc) seq from erm_quotation ) q
where q.seq = 1; -- return the first result, q.seq = 2 return the second result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment