join 3 tables (MySQL)
===

I want to join 3 tables (t1, t2, t3). I need to keep t1 (items and their properties) as it is (LEFT JOIN). 

Table t1 references t2 in order to retrieve more properties for each t1.item. However, in t2 there can be multiple entries of t1.item references each with individual values, ie. item1 (value1,value2), item2 (value3,value4), item1 (value5,value6) and so on. Table t2 contains refrences itself to t3 - t2 has a column named "style" with properties represented by numbers that need to be looked up in t3 (ie. number 1 --> property1, number 2 --> property2 etc.). For the task at hand I only want style properties with the reference number "1". The following code seems to do the trick: 

    $result = mysql_query("SELECT * FROM t1 LEFT JOIN (t2 INNER JOIN t3 ON t2.id= t3.id) ON t1.id=t2.id AND t2.type='1' ORDER BY t1.item $order ");

The thing is, there can still be two or more items with the same t1 refrence that have this same style attached to them, ie. item1 (value1, value2, style1), item1 (value3, value4, style1). Out of these items I want to extract only one, namely the one with the highest value. First I need to check each item's value pair and retrieve the highest amount out of those and then I need to compare those two item values. Something like this:

    (CASE WHEN MAX(t2.column_value1) > MAX(t2.column_value2) THEN t2.column_value1 ELSE t2.column_value2 END)

I just don't know how to put this to work. Any help would be appreciated. Thanks

