I would probably try a different approach, maybe something like this:
SELECT * FROM `log` WHERE `user` IN ( SELECT `user1` FROM `friendships` WHERE `user2` = @user AND `active` = 1 UNION ALL SELECT `user2` FROM `friendships` WHERE `user1` = @user AND `active` = 1 UNION ALL SELECT @user ) GROUP BY `arguments` ORDER BY `created` DESC
Although, to be honest, I would not choose columns that were not aggregated and not included in GROUP BY in such a query, although MySQL would allow me to do this.
Another alternative:
SELECT * FROM `log` WHERE `user` IN ( SELECT CASE `user1` WHEN @user THEN `user2` ELSE `user1` END AS `user` FROM `friendships` WHERE (`user1` = @user OR `user2` = @user) AND `active` = 1 UNION ALL SELECT @user ) GROUP BY `arguments` ORDER BY `created` DESC
source share