7 | | SELECT t.transaction_id, t.transaction_name, t.amount, t.net_amount, t.date, tg.tag_name, ta.account_name |
8 | | FROM transaction t |
9 | | LEFT JOIN tag tg ON t.tag_id = tg.tag_id |
10 | | JOIN transaction_account ta ON t.transaction_id = ta.transaction_account_id |
11 | | WHERE ta.user_id = 101 |
12 | | ORDER BY t.date DESC; |
| 7 | SELECT |
| 8 | t.transaction_id, |
| 9 | t.transaction_name, |
| 10 | t.amount, |
| 11 | t.net_amount, |
| 12 | t.date, |
| 13 | STRING_AGG(DISTINCT tg.tag_name, ', ') AS tag_names, -- Aggregate multiple tag names |
| 14 | ta.account_name |
| 15 | FROM |
| 16 | public."transaction" t |
| 17 | JOIN |
| 18 | public.transaction_breakdown tb ON t.transaction_id = tb.transaction_id |
| 19 | JOIN |
| 20 | public.transaction_account ta ON tb.transaction_account_id = ta.transaction_account_id |
| 21 | LEFT JOIN |
| 22 | public.tag_assigned_to_transaction tat ON t.transaction_id = tat.transaction_id |
| 23 | LEFT JOIN |
| 24 | public.tag tg ON tat.tag_id = tg.tag_id |
| 25 | WHERE |
| 26 | ta.user_id = 101 |
| 27 | GROUP BY |
| 28 | t.transaction_id, t.transaction_name, t.amount, t.net_amount, t.date, ta.account_name |
| 29 | ORDER BY |
| 30 | t.date DESC; |