sqldataexplorer

Shortest posts on a Stack Exchange site by body length with username of original poster (SEDE)


So I recently have been working on a SEDE query that outputs posts from a given Stack Exchange site that have bodies of less than 50 characters.

While I have figured out how to get the links to those posts, I would also like to get the usernames under which those questions were posted.

Here is my current code:

SELECT p.Id AS [Post Link], Len(Body) AS [Body Length], p.Score, p.ViewCount, p.Tags
FROM Posts p
WHERE Len(Body) < 50
AND p.PostTypeId = 1
ORDER BY Len(Body) DESC

What I have tried to do to get my desired result:

My question is: How can I also get the username of the original poster of the questions into its own column?


Revisions that include previous attempts (if it would be helpful to look at):


Solution

  • You just need to join to the Users table:

    SELECT p.Id          AS [Post Link]
         , u.DisplayName
         , len(p.Body)   AS [Body Length]
         , p.Score
         , p.ViewCount
         , p.Tags
      FROM Posts p
               join
           Users u on u.Id = p.OwnerUserId
     WHERE len(p.Body)  < 50
       AND p.PostTypeId = 1
     ORDER BY len(p.Body) DESC