>user_name, user_pk >>So, the above ecords from the Table1 should be in the query
>user_pk, user_email >>The column USER_EMAIL from the second table
>user_name, data_in >>Date_in - the last time this user logged in.
>USER_1 USER_1_EMAIL USER1_LASTDATE_IN >USER_2 USER_2_EMAIL USER2_LASTDATE_IN >>Here is what I tried
>select Table1.USER_NAME as USER_1, MAX(USER_EMAIL) as USER_1_EMAIL, MAX(DATE_IN) AS USER1_LASTDATE_IN FROM Table1 >LEFT JOIN Table3 on Table1.USER_NAME = Table3.USER_NAME GROUP BY Table1.USER_NAME >LEFT JOIN Table2 ON Table2.USER_PK = Table1.USER_PK >>The above works.
select Table1.USER_NAME as USER_1, USER_EMAIL as USER_1_EMAIL, LASTDATE AS USER1_LASTDATE_IN ; FROM Table1 ; LEFT JOIN (SELECT MAX(Date_IN) FROM Table3 WHERE Table3.USER_NAME = Table1.USER_NAME) ; LEFT JOIN Table2 ON Table2.USER_PK = Table1.USER_PKIf you're in SQL Server and the issue is that you need a different field from the one you're trying to maximize (for example, if you had a third column in Table3 that was the one you wanted in the result, but you wanted it from the record with the most recent date), then Christian's advice about using OVER is the way to go.