# Versuchen, eine Abfrage durchzuführen, um ausgefüllte benutzerdefinierte Felder zu finden

**URL:** <https://meta.discourse.org/t/trying-to-query-to-find-user-custom-fields-filled-out/86472>\
**Category:** Data & reporting\
**Tags:** sql-query, user-custom-fields\
**Created:** [30. April 2018 um 18:42 UTC](https://meta.discourse.org/t/trying-to-query-to-find-user-custom-fields-filled-out/86472 "2018-04-30T18:42:26Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [30. April 2018 um 23:37 UTC](https://meta.discourse.org/t/trying-to-query-to-find-user-custom-fields-filled-out/86472/3 "2018-04-30T23:37:58Z")

</div>

I’m sure there are better ways of approaching this, but this should work to give you a single row containing all of the fields for each user who has filled out at least one of your user fields.

```plaintext
WITH user_field_1 AS (
SELECT ucf.value,
ucf.user_id
FROM user_custom_fields ucf
WHERE ucf.name = 'user_field_1'
AND ucf.value IS NOT NULL
AND ucf.value != ''
),
user_field_2 AS (
SELECT ucf.value,
ucf.user_id
FROM user_custom_fields ucf
WHERE ucf.name = 'user_field_2'
AND ucf.value IS NOT NULL
AND ucf.value != ''
),
user_field_3 AS (
SELECT ucf.value,
ucf.user_id
FROM user_custom_fields ucf
WHERE ucf.name = 'user_field_3'
AND ucf.value IS NOT NULL
AND ucf.value != ''
),
user_field_4 AS (
SELECT ucf.value,
ucf.user_id
FROM user_custom_fields ucf
WHERE ucf.name = 'user_field_4'
AND ucf.value IS NOT NULL
AND ucf.value != ''
),
target_fields AS (
SELECT
u.id AS user_id,
uf1.value AS user_field_1,
uf2.value AS user_field_2,
uf3.value AS user_field_3,
uf4.value AS user_field_4
FROM users u
LEFT JOIN user_field_1 uf1
ON uf1.user_id = u.id
LEFT JOIN user_field_2 uf2
ON uf2.user_id = u.id
LEFT JOIN user_field_3 uf3
ON uf3.user_id = u.id
LEFT JOIN user_field_4 uf4
ON uf4.user_id = u.id
)

SELECT
*
FROM target_fields tf
WHERE tf.user_field_1 IS NOT NULL
OR tf.user_field_2 IS NOT NULL
OR tf.user_field_3 IS NOT NULL
OR tf.user_field_4 IS NOT NULL
ORDER BY tf.user_id

```

---

_[View the full topic](https://meta.discourse.org/t/trying-to-query-to-find-user-custom-fields-filled-out/86472)._
