One-time Instagram-like followings API Linq & SQL query

Job ID: 34805336

Budget: $10 – $30 USD

The task is to write an SQL query and LINQ equivalent that would return a list of followings but there are some requirements like it is on Instagram.

Scenario:

A user 'A' browses through user 'B' account and views a list of users the user 'B' follows

If 'B' follows 'A' then the account of 'A' should top the returned list.
If 'B' and 'A' has common followings ie (users they both follow), then that should be next in line in the returned list after item no 1.
Then other users from 'B' followings.

Considering the following table:

UserProfile (name, userId)
UserProfileMembers: (profileId, userId))

More information available upon starting
Related categories: SQL C# Programming PostgreSQL LINQ