Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Created August 13, 2015 15:46
Show Gist options
  • Save coreyjs/a606457e3becabded7b4 to your computer and use it in GitHub Desktop.
Save coreyjs/a606457e3becabded7b4 to your computer and use it in GitHub Desktop.
select order_Id from [order] o where(
o.order_id in (
select osh.order_id
from order_status_history osh
join order_status os on os.status_id = osh.status_id
inner join (
select order_id, MAX(effective_date) as updated
from order_status_history
group by order_id) as status on osh.order_id = status.order_id and osh.effective_date = status.updated
where (os.code in ( 'cart'))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment