SELECT DISTINCT ON (BugTask.id) BugTask.*
FROM BugTask, Bug, BugMessage, Message
WHERE
Bug.id = BugTask.bug
AND Bug.id = BugMessage.bug
AND BugMessage.message = Message.id
AND BugTask.status in (10, 15, 20, 21, 22, 25)
AND Bug.duplicateof IS NULL
AND Bug.private = FALSE
AND BugMessage.index > 0
AND Message.owner = 931129
ORDER BY BugTask.id;
SELECT DISTINCT ON (BugTask.id) BugTask.*
FROM BugTask, Bug, BugMessage, Message
WHERE
Bug.id = BugTask.bug
AND Bug.id = BugMessage.bug
AND BugMessage.message = Message.id
AND BugTask.status in (10, 15, 20, 21, 22, 25)
AND Bug.duplicateof IS NULL
AND Bug.private = FALSE
AND BugMessage.index > 0
AND Message.owner = 931129
ORDER BY BugTask.id;