I was hoping for some help on a query I am stuck on.
Basically I have the following table
id | tmpid | tmpyear | tmpone | tmptwo | tmpthree | tmptype 
1  | 2     | 9       | 33     | 26     | 12       | profit
2  | 2     | 9       | 32     | 10     | 2        | profit
3  | 2     | 9       | 55     | 14     | 10       | loss
4  | 2     | 9       | 16     | 12     | 4        | loss
5  | 2     | 10      | 12     | 19     | 3        | profit
I have no idea how to format a query which would return the rows with id 2 and id 5
Basically I want to select the whole row but I want distinct tmpid,tmpyear and tmptype
Queries I tried
Select * from table where tmpid = 2 and tmptype = 'profit'
This returns 3 rows however I dont want to return where tmpyear is duplicated which this query will return id 1 and 2. In case of duplicated year I would rather the query only returns the higher id ( returns id 2 and ignores id 1 ).
Select distinct tmpid,tmpyear,tmptype where tmptype = 'profit'
This query is nearly perfect , it returns the following
tmpid | tmpyear | tmptype 
2     | 9       | profit
2     | 10      | profit
So we have got rid of the one row with duplicate tmpyear however I also need the other information such as tmpone, tmptwo , tmpthree which is missing from this .
Apologies for the confusing question, I'm not sure how else I can explain it.
 
     
     
    