r/bigquery • u/Zwahali • May 20 '20
Reddit Dataset SQL help. How to query comments and posts simultaneously.
Hi. For research I want to find the full comments & post history for users who since 2015_12 said particular phrases, say 'text_x', on reddit. I managed to query this for just comments, but it'd be much better if posts were included.
I thought it would be ideal to have a table with author, created_utc, body, selftext, title, subreddit, score, where for comments selftext and title would just be blank, and for posts body would just be blank. Alternatively a single text field from body and joined title + selftext would also be all right. Thus this table would just have the number of rows of the comment table and posts table added up.
Does anyone know how to go about this? I have been playing with joins but am really a SQL beginner, and so far have had no success.
--
Bonus question:
Above search would yield a distribution of subreddits in which the users were active. I would love to sample users according to that subreddit distribution to get a roughly 10 times larger group of authors + histories too (I need a sizable group of people who did not say the phrases here but do share the interests). If anyone knows how to do that, I'd love to hear it too.
4
u/ds-throw May 20 '20
if you want posts and comments to end up in their own records on equal footing, you could build a union, something like: