# Query to filter users by sign-up 'custom fields'

**URL:** <https://meta.discourse.org/t/query-to-filter-users-by-sign-up-custom-fields/100837>\
**Category:** Data & reporting\
**Tags:** sql-query, user-custom-fields\
**Created:** [October 30, 2018, 1:50am UTC](https://meta.discourse.org/t/query-to-filter-users-by-sign-up-custom-fields/100837 "2018-10-30T01:50:50Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [January 17, 2022, 8:15pm UTC](https://meta.discourse.org/t/query-to-filter-users-by-sign-up-custom-fields/100837/12 "2022-01-17T20:15:45Z")

</div>

> [@cokestroke](#):
>
> which one of these queries would work if I had multiple custom fields and just wanted to return a list of users and their answers to those custom fields?

None of the above queries will give you exactly what you are looking for. Without writing a new query, the best approach would be to run the first query I posted multiple times. Run it one time for each of your custom fields. Enter the field’s name into the query’s `field_name` input. The query I’m referring to is this one:

```sql
--[params]
-- string :field_name

WITH ucf_name AS(
SELECT
CONCAT('user_field_', id) AS name
FROM user_fields
WHERE name = :field_name
)

SELECT
u.id AS user_id,
ucf.value
FROM users u
JOIN user_custom_fields ucf
ON ucf.user_id = u.id
WHERE ucf.name = (SELECT name FROM ucf_name)

```

---

_[View the full topic](https://meta.discourse.org/t/query-to-filter-users-by-sign-up-custom-fields/100837)._
