# A query for users with a custom title?

**URL:** <https://meta.discourse.org/t/a-query-for-users-with-a-custom-title/275004>\
**Category:** Data & reporting\
**Tags:** sql-query\
**Created:** [14. Oktober 2016 um 20:50 UTC](https://meta.discourse.org/t/a-query-for-users-with-a-custom-title/275004 "2016-10-14T20:50:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)\
**Post date:** [15. Oktober 2016 um 09:23 UTC](https://meta.discourse.org/t/a-query-for-users-with-a-custom-title/275004/2 "2016-10-15T09:23:31Z")

</div>

I don’t think this is strictly possible, because a custom title could be character-by-character identical to a badge granted one (possible of a badge the user doesn’t have).

Here’s a query that _might_ do what you want:

```sql
SELECT username FROM users
WHERE title IS NOT NULL

AND (
    SELECT count(*) FROM badges
    WHERE allow_title = true
    AND name = title
    ) = 0

AND (
    SELECT count(*) FROM groups
    WHERE groups.title = users.title
    ) = 0

```

It selects every title any user has, minus every title where a corresponding badge exists, minus every title that could come from a group membership. It does _not_ test whether the user has the badge or the group membership.

Maybe it does help you, at least as a starting point 🙂

---

_[View the full topic](https://meta.discourse.org/t/a-query-for-users-with-a-custom-title/275004)._
