SELECT DISTINCT Profiles.ID FROM (select * from Profiles RIGHT JOIN FriendList ON (FriendList.Profile = 15237) order by LastLoggedIn DESC ) as Profiles