I'm trying to join 3 tables together (Event, Symbol, Category). This is the basic design
Event Table:
Id | Title
-----------
1 | Testing
3 | Debugging
Symbol Table:
Event_Id | Symbol
-----------------
1 | TT
1 | UU
Category Table:
Event_Id | Category
--------------------
1 | XV
1 | XX
3 | XL
The Join query I have written is:
SELECT event.Id , STRING_AGG(symbol.symbol, ',') symbol, STRING_AGG(category.category, ',') as category
FROM Event as event
LEFT JOIN Category category ON event.publisherID = category.Id
LEFT JOIN Symbol symbol on event.publisherID = symbol.Id
GROUP BY event.Id
The results I get is:
Id | symbol | category
---------------------------------
1 | TT,UU,TT,UU | XV,XV,XX,XX
3 | NULL | XL
How do I make it so that there wont be duplicates for the symbol and category columns?