Join of two saved question with the grouping in them and custom columns causes an error

There are two saved question, both with filter and grouping within them. If one constructs new question with both of them, with all the fields from two questions, everything works fine. But if custom field (“test field”) is added, an error occurs: [Vertica]VJDBC ERROR: Column source.user_uid does not exist. In SQL for both cases it can be seen that indeed source.user_uid field (as well as “source”.“deposit_first_date”) are added. Why are they added and how can we get rid of this error?

CORRECT QUESTION:
SELECT “source”.“registration_date” AS “registration_date”, “source”.“count” AS “count”, “Question 6729”.“registration_date” AS “registration_date_2”,
“Question 6729”.“count” AS “count_2”
FROM (
SELECT date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”) AS “registration_date”,
count(distinct “rptbi”.“sse_client_dm_out”.“user_uid”) AS “count” FROM “rptbi”.“sse_client_dm_out”
WHERE “rptbi”.“sse_client_dm_out”.“registration_date” BETWEEN timestamp with time zone ‘2020-01-01 00:00:00.000Z’
AND timestamp with time zone ‘2020-07-31 00:00:00.000Z’
GROUP BY date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”)
ORDER BY date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”) ASC
) “source”
LEFT JOIN (
SELECT date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”) AS “registration_date”,
count(distinct “rptbi”.“sse_client_dm_out”.“user_uid”) AS “count” FROM “rptbi”.“sse_client_dm_out”
WHERE (“rptbi”.“sse_client_dm_out”.“deposit_first_date” IS NOT NULL AND “rptbi”.“sse_client_dm_out”.“registration_date” BETWEEN timestamp with time zone ‘2020-01-01 00:00:00.000Z’ AND timestamp with time zone ‘2020-07-31 00:00:00.000Z’)
GROUP BY date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”)
) “Question 6729”
ON “source”.“registration_date” = “Question 6729”.“registration_date”
LIMIT 1048576

INCORRECT QUESTION:
SELECT “source”.“registration_date” AS “registration_date”, “source”.“count” AS “count”, “source”.“test field” AS “test field”,
“source”.“registration_date” AS “registration_date_2”, “source”.“count” AS “count_2”
FROM
(
SELECT (“source”.“count” * “Question 6729”.“count”) AS “test field”, “source”.“registration_date” AS “registration_date”,
“Question 6729”.“registration_date” AS “registration_date_2”, “source”.“user_uid” AS “user_uid”,
“source”.“deposit_first_date” AS “deposit_first_date”, “source”.“registration_date” AS “registration_date_3”,
“source”.“count” AS “count”, “Question 6729”.“count” AS “count_2” FROM
(
SELECT date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”) AS “registration_date”,
count(distinct “rptbi”.“sse_client_dm_out”.“user_uid”) AS “count” FROM “rptbi”.“sse_client_dm_out”
WHERE “rptbi”.“sse_client_dm_out”.“registration_date” BETWEEN timestamp with time zone ‘2020-01-01 00:00:00.000Z’
AND timestamp with time zone ‘2020-07-31 00:00:00.000Z’
GROUP BY date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”
)
ORDER BY date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”) ASC
) “source”
LEFT JOIN (
SELECT date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”) AS “registration_date”,
count(distinct “rptbi”.“sse_client_dm_out”.“user_uid”) AS “count” FROM “rptbi”.“sse_client_dm_out”
WHERE (“rptbi”.“sse_client_dm_out”.“deposit_first_date” IS NOT NULL AND “rptbi”.“sse_client_dm_out”.“registration_date” BETWEEN timestamp with time zone ‘2020-01-01 00:00:00.000Z’ AND timestamp with time zone ‘2020-07-31 00:00:00.000Z’)
GROUP BY date_trunc(‘month’, “rptbi”.“sse_client_dm_out”.“registration_date”)
) “Question 6729”
ON “source”.“registration_date” = “Question 6729”.“registration_date”

) “source”
LIMIT 1048576

Hi @Alisa

Post “Diagnostic Info” from Admin > Troubleshooting.

It sounds like you’re seeing one of these issues - or one of the references in those issues - but it’s a little difficult to say for sure without more details on how the questions are constructed:
https://github.com/metabase/metabase/issues/12839
https://github.com/metabase/metabase/issues/12762