ID | user_id | name      | active
1  | 1       | Profile 1 | f
2  | 1       | Profile 2 | t
3  | 2       | Profile 3 | f
4  | 2       | Profile 4 | f
5  | 3       | Profile 5 | f
I'm using PostgreSQL. In my application,users can create multiple profiles and I want to select last distinct inactive profiles created by  each user. Also, if there is an active profile belongs to that user, it should not select any profile from that user -- that was the hard part for me.
What kind of SQL statement I should use in order to get the following results?
4  | 2       | Profile 4 | f
5  | 3       | Profile 5 | f
 
     
     
     
    