armtuk: Cheetah (Default)
armtuk ([personal profile] armtuk) wrote2009-03-04 12:38 am
Entry tags:

The most Awesome SQL

If you can even figure out how this works, Kudos. I'm pretty proud I figured out how to make this. There might be better ways, but this way works, and gets me what I need:

select * from task x, (select p.project_id, u.workflow_id, (select min(due_date) as min_due_date from task t where t.workflow_id=u.workflow_id) as min_due_date from task u, workflow p where u.workflow_id=p.workflow_id group by u.workflow_id, p.project_id) y where x.due_date=y.min_due_date and x.workflow_id=y.workflow_id;

Muhahahaha.