skip to Main Content

Table 1 :

X , Y , Z 
10, 12, 14
20, 17, 18

Table 2:

X ,  Y, Z
100, 75, 80
375, 100, 122

I have 7 such tables. Expected outcome is combining only all rows. Which Join should I use?

Final Table

X , Y , Z 
10, 12, 14
20, 17, 18
100, 75, 80
375, 100, 122

2

Answers


  1. Check out SQL Union

    https://www.w3schools.com/sql/sql_union.asp

    This isn’t technically a join on common data, rather a way to combine the results from tables with the same schema (column definitions)

    Login or Signup to reply.
  2. The query you need is to union together the result of each query:

    Select X, Y, Z
    from t1
    union all
    Select X, Y, Z
    from t2
    union all.... ;
    

    You can remove all if you need to exclude any duplicate rows, but if you don’t keep union all as removing duplicates carries additional overhead.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search