(
    SELECT b.*
    FROM users       AS a,
         friendships AS b,
         users       AS c
    WHERE a.userId      = b.activeId AND
          c.userId      = b.passiveId AND
          a.remove      = false AND
          b.activeId    IN /*activeIds*/(0,1,2) AND
          b.passiveId   = /*passiveId*/0 AND
          b.accept      = true AND
          b.removedTime = 0 AND
          c.protect     = true AND
          c.remove      = false
    ORDER BY activeId DESC
) UNION ALL (
    SELECT b.*
    FROM users       AS a,
         friendships AS b,
         users       AS c
    WHERE a.userId      = b.activeId AND
          c.userId      = b.passiveId AND
          a.remove      = false AND
          b.activeId    IN /*activeIds*/(0,1,2) AND
          b.passiveId   = /*passiveId*/0 AND
          b.removedTime = 0 AND
          a.protect     = false AND
          a.remove      = false
    ORDER BY activeId DESC
)
ORDER BY activeId DESC
LIMIT /*offset*/0,/*limit*/1