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. Making with values of two rows, two entries in a new table.

Making with values of two rows, two entries in a new table.

Scheduled Pinned Locked Moved Database
4 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.
  • N Offline
    N Offline
    neus83
    wrote on last edited by
    #1

    Hi all. I would like to make from three only two rows. I hope someone can helps me to put values which are not "null" to a new row. This is the table which exisits: Table "MACandDNS": NAME | ETH0 | ETH1 | hugo | 000011223333 | 000011223334 | sassy | 000013323333 | 000211223334 | jan | 985555111113 | | kevin |

    C J 2 Replies Last reply
    0
    • N neus83

      Hi all. I would like to make from three only two rows. I hope someone can helps me to put values which are not "null" to a new row. This is the table which exisits: Table "MACandDNS": NAME | ETH0 | ETH1 | hugo | 000011223333 | 000011223334 | sassy | 000013323333 | 000211223334 | jan | 985555111113 | | kevin |

      C Offline
      C Offline
      Corporal Agarn
      wrote on last edited by
      #2

      Maybe something like?

      INSERT INTO MACandDNSnew
      SELECT NAME, ETH0 AS ETH
      FROM firsttable
      WHERE ETH0 IS NOT NULL
      UNION
      SELECT NAME, ETH1 AS ETH
      FROM firsttable
      WHERE ETH2 IS NOT NULL

      1 Reply Last reply
      0
      • N neus83

        Hi all. I would like to make from three only two rows. I hope someone can helps me to put values which are not "null" to a new row. This is the table which exisits: Table "MACandDNS": NAME | ETH0 | ETH1 | hugo | 000011223333 | 000011223334 | sassy | 000013323333 | 000211223334 | jan | 985555111113 | | kevin |

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #3

        This is a bit ugly, but it should work. Atleast if I have understood you correct.

        SELECT NAME,ETH0 as ETH
        FROM MACandDNS
        WHERE ETH0 IS NOT NULL
        AND ETH1 IS NOT NULL
        UNION
        SELECT NAME,ETH1 as ETH
        FROM MACandDNS
        WHERE ETH0 IS NOT NULL
        AND ETH1 IS NOT NULL

        Note that if ETH0 and ETH1 is the same for one name then you get only one row. If that's a problem you can use UNION ALL but then the rows for certain won't be unique

        "When did ignorance become a point of view" - Dilbert

        N 1 Reply Last reply
        0
        • J Jorgen Andersson

          This is a bit ugly, but it should work. Atleast if I have understood you correct.

          SELECT NAME,ETH0 as ETH
          FROM MACandDNS
          WHERE ETH0 IS NOT NULL
          AND ETH1 IS NOT NULL
          UNION
          SELECT NAME,ETH1 as ETH
          FROM MACandDNS
          WHERE ETH0 IS NOT NULL
          AND ETH1 IS NOT NULL

          Note that if ETH0 and ETH1 is the same for one name then you get only one row. If that's a problem you can use UNION ALL but then the rows for certain won't be unique

          "When did ignorance become a point of view" - Dilbert

          N Offline
          N Offline
          neus83
          wrote on last edited by
          #4

          Thank you all, it helped me really much :) :)

          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