I need to do a subquery in BigQuery as follows
SELECT
*
FROM
table1
WHERE
user_id IN
(
SELECT
DISTINCT user_id
FROM table1
WHERE
date >= '2023-01-01'
);
I tried the solution in this post
MySQL DELETE FROM with subquery as condition
and my query turns into this
SELECT e.*
FROM table1 e
WHERE user_id IN (SELECT user_id
FROM (SELECT DISTINCT user_id
FROM table1
WHERE date >= '2023-01-01') x);
but this came up
Correlated subqueries that reference other tables are not supported unless they can be de-correlated, such as by transforming them into an efficient JOIN.
How can I fix my query?
ps: my table looks like
user_id | balance | date |
---|---|---|
1 | 0.01 | 2022-01-01 |
1 | 0.02 | 2023-01-02 |
2 | 0.03 | 2022-01-01 |
2 | 0.04 | 2022-12-31 |
3 | 0.05 | 2023-12-31 |
I need all users data whose latest record is later than 2023-01-01, which is
user_id | balance | date |
---|---|---|
1 | 0.01 | 2022-01-01 |
1 | 0.02 | 2023-01-02 |
3 | 0.05 | 2023-12-31 |