Here's the SQL query that lists all thoughts by the number of linked thoughts:
SELECT Count(Thoughts.Name) AS Total, Thoughts.NameYou can use something like this to get the info from the main database.
FROM Thoughts INNER JOIN Links ON Thoughts.Id = Links.ThoughtIdA
GROUP BY Thoughts.Name
ORDER BY Count(Thoughts.Name) DESC;