Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Union statement

Union statement

Scheduled Pinned Locked Moved Database
databasehelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    phokojoe
    wrote on last edited by
    #1

    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

    M C 2 Replies Last reply
    0
    • P 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

      M Offline
      M Offline
      mr_12345
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • P 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

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        To clarify Table1

        az azz
        1 23
        . 56
        2 ..
        3 76

        You want the output to look like this: Table2

        a1 a2 a3 a4
        1 23 . 56
        2 .. 3 76

        There 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups