How do I extract row/column elements from multiple tables with same schema in single query My question is as follows: Given that I have three tables with exactly the same column names and exactly the same keys for the "name" column e.g.

Table r
name | A | B | C 
-----------------
elem1| 12| 41| 23
elem2|  5| 16| 94
elem3| 42| 93| 11


Table t
name | A | B | C
-----------------
elem1|  9|  8|  1
elem2|  3|  6|  5
elem3|  2|  1|  3


Table p
name | A | B | C
-----------------
elem1| 21| 14| 32
elem2|  5| 61| 49
elem3| 24| 36| 11


how can i merge all these tables into a set of rows as follows in a single query:

output
name | column | value
--------------------------
elem1|      A | "12,9,21"
elem1|      B | "41,8,14"
elem1|      C | "23,1,32"
elem2|      A | "5,3,5"
...  | ...    | ...
elem3|      C | "11,3,11"


or if it is simpler:

output
name |       A |       B |       C
------------------------------------
elem1|"12,9,21"|"41,8,14"|"23,1,32"
elem2|  "5,3,5"|"16,6,61"|"94,5,49"
elem3|"42,2,24"|"93,1,36"|"11,3,11"
Simplest way would be to use UNION:

SELECT * FROM A
     UNION
SELECT * FROM B
     UNION
SELECT * FROM C


or use a JOIN:

SELECT *
FROM A
FULL OUTER JOIN B
ON &lt; A.name=B.name&gt;;


Read more about joins

Hope this helps.