Hello there folks,I just want to modify an existing query (with lots of joins), grouping the results by a specific column. I don't care about the occurance order(fisrt,last,min etc) Using MIN() in all columns and GROUP BY (one col), does it gives me back the correct results for each returned column (remember, several joins)? Secondly, how do I use GROUP BY (one col) if there is an aggregate subquery (nested select as a column)?Thanks a lot in advance, b&gs!Here Is The Modified Statement:<<The original statement was the same except that I have added MIN() on all columns and a GROUP BY clause.ECOM is the distinction column.I think the query works fine, as long as I don't add the first column (RESERVED) which is a subquery>>SELECT (SELECT ISNULL(SUM(ISNULL(Z1.QTY1,0)-Z1.QTY1COV-Z1.QTY1CANC)/ISNULL(A.MU21,0),0) FROM MTRLINES Z1, RESTMODE Z2 WHERE Z1.MTRL = A.MTRL AND Z1.PENDING = 1 AND Z2.RESTCATEG = 2 AND Z1.COMPANY = Z2.COMPANY AND Z1.RESTMODE = Z2.RESTMODE) AS RESERVED,MIN(UTB.NAME) AS DIMENSION, MIN(ROUND(ISNULL(C.QTY2, 0), 0)) AS WHOUSE_TODAY, MIN(UNITTYPE.NAME) AS UNITNAME, B.VARCHAR05 AS ECOM, MIN(A.NAME) AS NAME, MIN(A.PRICER) AS PRICE, MIN(A.PRICER01) AS WEBPRICE, MIN(A.REMARKS) AS REMARKS, MIN(A.SETITEM) AS SETITEM, MIN(COUNTRY.NAME) AS COUNTRYNAME, MIN(A.MTRL) AS PRD_ID, MIN(A.CODE), MIN(ISNULL(A.MU21, 0)) AS MU, MIN(A.MTRMODEL) AS MODEL FROM MTRL AS A LEFT OUTER JOIN MTREXTRA AS B ON A.MTRL = B.MTRL LEFT OUTER JOIN MTRDATA AS C ON A.MTRL = C.MTRL LEFT OUTER JOIN UTBL01 AS UTB ON B.UTBL01 = UTB.UTBL01 AND C.FISCPRD = 2010 LEFT OUTER JOIN MTRUNIT AS UNITTYPE ON A.MTRUNIT1=UNITTYPE.MTRUNIT AND UNITTYPE.COMPANY=1 LEFT OUTER JOIN COUNTRY AS COUNTRY ON A.COUNTRY=COUNTRY.COUNTRY WHERE (A.COMPANY = 1) AND (A.SODTYPE = 51) AND (A.ISACTIVE = 1) AND (UTB.SODTYPE = 51) AND (UTB.COMPANY = 1) AND (NOT (B.VARCHAR05 IS NULL)) AND (NOT (B.VARCHAR05 = '')) AND (A.MTRMODEL = 2045) GROUP BY B.VARCHAR05ORDER BY ECOM, DIMENSION