Completed the query for getting friend threads from the database