I am trying to create a query that lists every User and the users' transactionId's in an additional column. Every user can have multiple transactions where User.userId = Transaction.userId. When I use the query below I receive an error where it does not recognise the alias U1 for User:
Error Code: 1054. Unknown column 'U1.userId' in 'where clause'
The subquery sub1 is used to narrow down the results that will be concatenated by GROUP_CONCAT.
There are similar questions that cover aliases not being found but none of them in a sub-sub-query for GROUP_CONCAT.
SELECT
*,
(
SELECT
GROUP_CONCAT(transactionId SEPARATOR ',')
FROM (
SELECT * FROM Transaction AS T1
WHERE T1.userId = U1.userId
) as sub1
) as transactionIds
FROM
User as U1
Does anyone know how to achieve the desired result? Rows of Users with an additional column summarising the users' transactionIds.