I'm trying to generate a SQL query that can join two tables together and return the result .. but the second table is 'flattened'. I'm not sure if that's the correct technical term. Is it denormalized?
Anyways, can someone suggest how I could do this?
Table: Users
UserId Name
1 Pure.Krome
2 John
3 Jill
4 Jane
Table: UserAliases
UserAliasId UserId Alias
1 1 Idiot
2 1 PewPew
3 3 BlahBlahBlah
Desired results
UserId Name Aliases
1 Pure.Krome Idiot PewPew
2 John
3 Jill BlahBlahBlah
4 Jane
Please note:
- A user does NOT need to have an alias. So that's a zero->many relationship (
outer join
) - The delimiter for the flattening of the 2nd table is a SPACE. If an alias has a space, bad luck for me. (Consider it, bad data).
Another example of my problem is to think of a StackOverflow question + tags.