Union statement
-
I have a table call it table1 with say 2 columns az and azz az azz 1,23,.,56 2,..,3,76 I have to insert this data into a new table, table2 with 4 columns, a1,a2,a3,a4 such that a1 a2 a3 a4 1 23 . 56 2 .. 3 76 but after running the stored procedure wich takes the columns in table az union azz into table2, I get 4 rows instead of the 2 rows as shown above. What am I doing wrong. Help! phokojoe
-
I have a table call it table1 with say 2 columns az and azz az azz 1,23,.,56 2,..,3,76 I have to insert this data into a new table, table2 with 4 columns, a1,a2,a3,a4 such that a1 a2 a3 a4 1 23 . 56 2 .. 3 76 but after running the stored procedure wich takes the columns in table az union azz into table2, I get 4 rows instead of the 2 rows as shown above. What am I doing wrong. Help! phokojoe
Union does not work for what you are trying to do. You will need join the tables. Union statement allows the results (rows) of 2 queries to be 'Unioned' together to create one query. Your example above I don't understand how the records need to be entered into table4 Table 1 az | azz ----------- 1 | 5 4 | 9 8 | 11 15 | 22 What should table 2 look like after this query? Mike Lasseter
-
I have a table call it table1 with say 2 columns az and azz az azz 1,23,.,56 2,..,3,76 I have to insert this data into a new table, table2 with 4 columns, a1,a2,a3,a4 such that a1 a2 a3 a4 1 23 . 56 2 .. 3 76 but after running the stored procedure wich takes the columns in table az union azz into table2, I get 4 rows instead of the 2 rows as shown above. What am I doing wrong. Help! phokojoe
To clarify Table1
az azz
1 23
. 56
2 ..
3 76You want the output to look like this: Table2
a1 a2 a3 a4
1 23 . 56
2 .. 3 76There is no obvious logical relationship between table1 and table2 other than rows 1 and 2 from table 1 become row 1 of table2 and rows 3 and 4 from table1 become row 2 of table2. Databases are set based (there is no intrinsic order of the rows in the database - obviously there appears to an order due to the implementation, but that is, strictly speaking, an illusion) so there needs to be some element in the source table that can be used to describe order.
phokojoe wrote:
after running the stored procedure wich takes the columns in table az union azz into table2, I get 4 rows instead of the 2 rows as shown above. What am I doing wrong.
Without seeing your code I cannot tell you what you are doing wrong. However, I don't think I'd use a union to pivot the values in a table. Please show us your code and describe the relationship between the first and second table.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog