Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

  • While p.OwnerUserId does produce a new column, it only produces the given user IDs, while I would like the username specifically.
  • However, if I change p.OwnerUserId to p.OwnerDisplayName, this only produces a blank column with nothing in it.
  • It also seems like if I try to call u.OwnerDisplayName, it produces the error

    Line 1: The multi-part identifier "u.OwnerDisplayName" could not be bound.

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading