# Which table holds the post URL?

**URL:** https://meta.discourse.org/t/which-table-holds-the-post-url/178333
**Category:** Development
**Created:** [February 3, 2021, 10:13pm UTC](https://meta.discourse.org/t/which-table-holds-the-post-url/178333 "2021-02-03T22:13:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rmoff](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rmoff/32/200297_2.png) [@rmoff](https://meta.discourse.org/u/rmoff)
#### Post date: [February 3, 2021, 10:13pm UTC](https://meta.discourse.org/t/which-table-holds-the-post-url/178333/1 "2021-02-03T22:13:48Z")

</div>

I’m using the [data explorer](https://meta.discourse.org/t/32566?silent=true) to build a query which shows a user’s posts - which table can I use to return the URL of the post? I assumed it would be on `posts` but I don’t see it.

This is my query so far

```sql
SELECT u.email,c.name as post_category
 FROM posts p
left join user_emails u on p.user_id = u.user_id
left join topics t on p.topic_id=t.id
left join categories c on t.category_id = c.id
where p.created_at < '2021-03-01T00:00:00.000Z'
    GROUP BY
       u.email,u.user_id,c.name

```

thanks.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 3, 2021, 10:17pm UTC](https://meta.discourse.org/t/which-table-holds-the-post-url/178333/2 "2021-02-03T22:17:55Z")

</div>

In SQL it is

```sql
'/t/-' || topics.id || '/' || posts.post_number

```

Which on your example would be

```sql
SELECT u.email,c.name as post_category, '/t/-' || t.id || '/' || p.post_number as post_url
 FROM posts p
left join user_emails u on p.user_id = u.user_id
left join topics t on p.topic_id=t.id
left join categories c on t.category_id = c.id
where p.created_at < '2021-03-01T00:00:00.000Z'
    GROUP BY
       u.email,u.user_id,c.name

```

---

<div class="post-metadata">

### Author: ![rmoff](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rmoff/32/200297_2.png) [@rmoff](https://meta.discourse.org/u/rmoff)
#### Post date: [February 4, 2021, 10:00am UTC](https://meta.discourse.org/t/which-table-holds-the-post-url/178333/3 "2021-02-04T10:00:03Z")

</div>

Thanks, that’s great.

FWIW with the hyphen it didn’t work, so instead of this:

```sql
'/t-/' || topics.id || '/' || posts.post_number

```

I used

```sql
'/t/' || topics.id || '/' || posts.post_number

```

All sorted 👍
