# SQL query for users who have posted on a date (or date range)

**URL:** <https://meta.discourse.org/t/sql-query-for-users-who-have-posted-on-a-date-or-date-range/99301>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [October 11, 2018, 4:00pm UTC](https://meta.discourse.org/t/sql-query-for-users-who-have-posted-on-a-date-or-date-range/99301 "2018-10-11T16:00:37Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![cjk77](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cjk77/32/151779_2.png) [@cjk77](https://meta.discourse.org/u/cjk77)\
**Post date:** [October 18, 2018, 11:30am UTC](https://meta.discourse.org/t/sql-query-for-users-who-have-posted-on-a-date-or-date-range/99301/8 "2018-10-18T11:30:06Z")

</div>

So it turns out to be easier than I thought! This seems to accomplish what I wanted:

```plaintext
SELECT DISTINCT p.user_id AS user_id
FROM posts p
WHERE p.created_at > make_timestamp(2018, 10, 16, 0, 0, 0)
AND p.created_at < make_timestamp(2018, 10, 17, 0, 0, 0)

```

When I rewrote the query for use with a badge, it looked like this:

```plaintext
SELECT DISTINCT p.user_id AS user_id, created_at AS granted_at, NULL AS post_id
FROM posts p
WHERE p.created_at > make_timestamp(2018, 10, 15, 0, 0, 0)
AND p.created_at < make_timestamp(2018, 10, 16, 0, 0, 0)

```

The “DISTINCT” keyword doesn’t work quite so well here because of the added fields, so I get dupes of the various users who’ve posted during the specified time period. I’ve unchecked the “Badge can be awarded multiple times” option, so I think that’s ok. Am I right?

---

_[View the full topic](https://meta.discourse.org/t/sql-query-for-users-who-have-posted-on-a-date-or-date-range/99301)._
