I have following three tables, from which I would like to get a specific result
TableA
key1 key2
-------------
121 4
131 4
141 5
151 3
161 3
171 6
181 6
191 6
... ...
TableB:
key1 key3
-------------
121 1001
131 1111
141 1111
151 1222
161 1222
171 1234
181 1001
191 1111
... ...
TableC:
key3 key4
-------------
1001 "aa"
1111 "gg"
1222 "hh"
1234 "jj"
... ...
I want a SQL query (which could use inner join) to give me the following result:
key2 key4
-------------------------
3 "hh"
4 "aa", "gg"
5 "gg"
6 "aa", "gg", "jj"
Microsoft SQL Server 2012