I want to have my list of “Users_Who_Replied_To_A_Topic” Include the user’s NAME.
I tried to follow a convention from another thread, which makes these Data Explorer queries include additional information but it didn’t work when I applied the same syntax.
Here’s the query I’m running right now, which only returns they “username” of those who replied to a topic…
-- https://meta.discourse.org/t/68756/8?u=sidv
-- [params]
-- topic_id :topic_id = 536
SELECT u.username
FROM badge_posts p
JOIN topics t ON p.topic_id = t.id
JOIN users u ON p.user_id = u.id
WHERE t.id = :topic_id
GROUP BY p.user_id,u.username
Thanks for the quick help on this, Jay! I updated to the following, per your suggestion:
SELECT u.username, u.name
FROM badge_posts p
JOIN topics t ON p.topic_id = t.id
JOIN users u ON p.user_id = u.id
WHERE t.id = :topic_id
GROUP BY p.user_id,u.username
… then got this error…
PG::GroupingError: ERROR: column "u.name" must appear in the GROUP BY clause or be used in an aggregate function
LINE 12: SELECT u.username, u.name
So I changed the query to the following and it worked like a charm!
SELECT u.username, u.name
FROM badge_posts p
JOIN topics t ON p.topic_id = t.id
JOIN users u ON p.user_id = u.id
WHERE t.id = :topic_id
GROUP BY p.user_id,u.username,u.name
So from my original snippet, I added the following:
To the “SELECT” line: , u.name
To the “GROUP BY” line: ,u.name
Thanks again, @pfaffman for helping me with this syntax!