I checked this site for code to stack two tables (put the results from one table beneath the results from another) where the column names are different. I know that UNION ALL works when the names are the same.. and I KNOW THAT UNION ALL with an assignment for the column names that are missing from one table works when one table has more info than the other.. but what if the column names are different? like what if in one table the column name is CHP and in another it is "CHILD HEALTH PLUS" and I need those two columns to be stacked on top of one another?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
A UNION can be used as long as the datatypes of the columns are the same. It doesn't matter if the column names are different.
If you want to know which table the records are coming from, then you can add another field that will distinguish the rows:
what sql language? mysql/sql server?
mysql doesn't require that the column names be the same, but you could always use 'AS' to match up the column names eg.
EDIT: i just spotted the '2008' in the post title - is that sql server 2008? in any case, sql server doesn't seem to care re. column names either.