After many attempts, I know it's close but just can't seem to find the correct way.Table structure:RowID ItemName QuoteName Revision ShipToID1 ABC QABC 0 19962 ABC QABC 1 19963 ABC QABC 2 19964 XYZ123 QXYZ123 0 19965 XYZ123 QXYZ123 1 19966 KKJTT QKKJTT 0 2056
The sql should bring back two (2) rows but it's bringing back five (5).SELECT i.*FROM tblItems iINNER JOIN(SELECT rowid, MAX(revision) AS MaxRevision, CASE WHEN LEN(ItemName) > 3 THEN ItemName ELSE QuoteName END AS ItemNameFROM tblItemsGROUP BY rowid, ItemName, QuoteName) jn ON i.rowid = jn.rowid AND i.revision = jn.MaxRevisionWHERE i.ShipToID = 1996ORDER BY ItemName
Just can't seem to get only the MAX(Revision).Any suggestions are welcome.Thanks!!