Tuning query to remove joins for reporting This is the query I was sent. There is currently no data in the system as I was converting this query from teradata to SQL server.

SELECT user_id FROM user_table
LEFT OUTER JOIN
(
SELECT user_id , MIN(event_date) FROM event_table WHERE event_code='859' GROUP BY user_id
) join_859
ON user_table.user_id = join_859.user_id
LEFT OUTER JOIN
(
SELECT user_id , MIN(event_date) FROM event_table WHERE event_code='223' GROUP BY user_id
) join_223
ON user_table.user_id = join_223.user_id


Would the following query return the same results and perform better?

SELECT user_table.user_id, event_table.event_date 
FROM user_table
LEFT OUTER JOIN event_table ON user_table.user_id = event_table.user_id 
WHERE event_table.event_code IN (
    '223', 
    '859'
)
No it wouldn't (that is, it's not logically equivalent. Performance would probably be better though). Two reasons:


Both of the subqueries are aggregating to get the minimum event_date.
The second subquery (join_223) is an OUTER JOIN, not an INNER JOIN.


Incidentally, you have a repeated ON ON in the last line of the original query.