Reputation: 31
so I came across an issue when creating a view because I need to get values from two tables but use the field (sorry if that's not worded correctly) for example - table1 has legacy users table2 has current users
and the statement goes like this
select t1.firstname, t1.lastname from table1 t1;
is there a way to get first and last names from table two to show in the same result columns as table one? I know I could join the second table in and get the results as another column ex-
select t1.firstname, t1.lastname, t2.firstname, t2.lastname from table1 t1, table2 t2
sorry again if what I'm describing is convoluted
Upvotes: 0
Views: 117
Reputation: 3970
Yes, using union all
to combine rows as long as you have same no of columns with same types aligned to the queries to be unioned. Also, you could replace Union All
to UNION
in case you don't want duplicates but in case you want both tables records so as to show records exists in both tables can keep union all
select t1.firstname, t1.lastname from table1 t1
Union all
select t2.firstname, t2.lastname
from table2 t2
Upvotes: 2