# Last 7 days of topics

**URL:** https://meta.discourse.org/t/last-7-days-of-topics/85103
**Category:** Support
**Created:** [April 11, 2018, 6:52pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103 "2018-04-11T18:52:42Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![adamprocter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamprocter/32/120116_2.png) [@adamprocter](https://meta.discourse.org/u/adamprocter)
#### Post date: [April 11, 2018, 6:52pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/1 "2018-04-11T18:52:42Z")

</div>

Is there a way I get a quick list of topics that have been either created or updated in the last 7 days on my own discourse please?

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [April 12, 2018, 12:35am UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/2 "2018-04-12T00:35:13Z")

</div>

Do you have the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin?

---

<div class="post-metadata">

### Author: ![adamprocter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamprocter/32/120116_2.png) [@adamprocter](https://meta.discourse.org/u/adamprocter)
#### Post date: [April 12, 2018, 8:50am UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/3 "2018-04-12T08:50:10Z")

</div>

Thanks. No I didn’t know about that cool. Now to write the correct query

---

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [April 12, 2018, 5:42pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/4 "2018-04-12T17:42:09Z")

</div>

Did you create one?

If not, check this query:

```sql
--[params]
--string :interval = 1 week
--int :limit
SELECT id, title, created_at as posted
FROM topics
WHERE age(created_at) < interval :interval
AND archetype != 'private_message'
GROUP BY id
ORDER BY created_at DESC
LIMIT :limit

```

_[List updated](https://github.com/SidVal/discourse-data-explorer/blob/queries/querys.md)_ 🚀

---

<div class="post-metadata">

### Author: ![adamprocter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamprocter/32/120116_2.png) [@adamprocter](https://meta.discourse.org/u/adamprocter)
#### Post date: [April 12, 2018, 6:45pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/5 "2018-04-12T18:45:46Z")

</div>

Thanks. Have managed to install plug in. So will try this next. 👍

---

<div class="post-metadata">

### Author: ![adamprocter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/adamprocter/32/120116_2.png) [@adamprocter](https://meta.discourse.org/u/adamprocter)
#### Post date: [April 13, 2018, 7:38am UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/6 "2018-04-13T07:38:54Z")

</div>

thank you, this seems to be working, I assume limit is the number of results returned ? in case there are 1000’s ?

How could I include URL in the results? i see this is not in posts and there are a few different one

---

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [April 13, 2018, 12:24pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/7 "2018-04-13T12:24:14Z")

</div>

> [@adamprocter](#):
>
> I assume limit is the number of results returned ? in case there are 1000’s ?

Limit is the number of results returned and you must SET the limit on your query before run it.  
See this:

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/8/e8e2484b017d6778449d6dcd65e7cd42fdb12fde.png)

> [@adamprocter](#):
>
> How could I include URL in the results?

Try this:

```sql
--[params]
--string :interval = 1 week
--int :limit
SELECT tu.topic_id, t.title, t.created_at as posted
FROM topics t, topic_users tu
WHERE t.id = tu.topic_id 
AND age(t.created_at) < interval :interval
AND t.archetype != 'private_message'
GROUP BY tu.topic_id, t.title, t.created_at
ORDER BY t.created_at DESC
LIMIT :limit

```

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [April 13, 2018, 7:37pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/8 "2018-04-13T19:37:15Z")

</div>

> [@SidV](#):
>
> Try this:

Something like this should display a link in the results if you want that instead of the URL.

```plaintext
CONCAT('<a href = "/t/', topics.id, '">', topics.title) 
   AS html$topic

```

---

<div class="post-metadata">

### Author: ![SidV](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sidv/32/119460_2.png) [@SidV](https://meta.discourse.org/u/SidV)
#### Post date: [April 14, 2018, 5:00pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/9 "2018-04-14T17:00:23Z")

</div>

Great idea @Mittineague !

I took your code and add some new code 😉

I tested, works like a charm

```sql
--[params]
--string :interval = 1 week
--int :limit
SELECT id, 
CONCAT('<a href = "/t/', id, '">', title, '</a>') 
   AS html$topic,
   created_at as posted
FROM topics
WHERE age(created_at) < interval :interval
AND archetype != 'private_message'
GROUP BY id
ORDER BY created_at DESC
LIMIT :limit

```

_[v1.1 added](https://github.com/SidVal/discourse-data-explorer/blob/queries/queries/list-topics-week.sql)_ 🚀

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/last-7-days-of-topics/85103/10 "2024-06-08T12:37:37Z")

</div>

This topic was automatically closed after 2249 days. New replies are no longer allowed.
