I am having difficulty converting a view from T-SQL to Postgresql as it relates to the aggregate functions.
Here is my original SQL query:
SELECT TOP (100) PERCENT 
    thread_id, 
    MIN(message_id) AS message_id,  
    MIN(parent_message_id) AS parent_message_id, 
    MIN(created_at) AS initialResponse
FROM 
    dbo.bi_linear_thread
WHERE 
    LEFT([subject], 5) LIKE '%RE:%' AND parent_message_id IS NOT NULL
GROUP BY 
    thread_id
ORDER BY 
    thread_id
I have attempted to utilize the window function of:
first_value(message_id) OVER (Partition BY message_id ORDER BY messageid)
but continue to get incorrect returns.
Thoughts?
Edit for more context
-- after the answer provided. Hopeful this is helpful to others.
Needed to read the first line in a group that excluded the first record in a hierarchal order of threads to replies.
thread_id represents the thread.
message_id represents any message type whether a reply/original message. parent_message_id represents the original message in the thread.
"RE:" is a specified format for replies regardless whether nested or not in the subject field.
 
     
    