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. possible to get results of 3 different tables in 1 set of column results?

possible to get results of 3 different tables in 1 set of column results?

Scheduled Pinned Locked Moved Database
salesquestion
5 Posts 4 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.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I painted myself into a corner here. Was going to do a join, but realized I had nothing to join. Is it possible to get this result in 1 set?

    SELECT
    cc.ID
    , cc.CustomerID
    , cc.SessionID
    , cc.LoginID
    , cc.CardLabel
    , cc.CardBrand
    , cc.CardName
    , cc.CardNumber
    , cc.ExpMonth
    , cc.ExpYear
    , cc.CVV2
    , ba.Name1
    , ba.Name2
    , ba.CompanyName
    , ba.StreetAddress1
    , ba.StreetAddress2
    , ba.City
    , ba.StateCode
    , ba.PostalCode
    , ba.CountryCode
    , ba.Phone
    , sa.Name1
    , sa.Name2
    , sa.CompanyName
    , sa.StreetAddress1
    , sa.StreetAddress2
    , sa.City
    , sa.StateCode
    , sa.PostalCode
    , sa.CountryCode
    , sa.Phone
    FROM CUSTOMER_CARDDATA cc
    WHERE cc.ID = @CC_ID

    FROM CUSTOMER_BILLING_ADDRESS ba
    WHERE ba.ID = @BA_ID

    FROM CUSTOMER_SHIPPING_ADDRESS sa
    WHERE sa.ID = @SA_ID

    M L S 3 Replies Last reply
    0
    • J jkirkerx

      I painted myself into a corner here. Was going to do a join, but realized I had nothing to join. Is it possible to get this result in 1 set?

      SELECT
      cc.ID
      , cc.CustomerID
      , cc.SessionID
      , cc.LoginID
      , cc.CardLabel
      , cc.CardBrand
      , cc.CardName
      , cc.CardNumber
      , cc.ExpMonth
      , cc.ExpYear
      , cc.CVV2
      , ba.Name1
      , ba.Name2
      , ba.CompanyName
      , ba.StreetAddress1
      , ba.StreetAddress2
      , ba.City
      , ba.StateCode
      , ba.PostalCode
      , ba.CountryCode
      , ba.Phone
      , sa.Name1
      , sa.Name2
      , sa.CompanyName
      , sa.StreetAddress1
      , sa.StreetAddress2
      , sa.City
      , sa.StateCode
      , sa.PostalCode
      , sa.CountryCode
      , sa.Phone
      FROM CUSTOMER_CARDDATA cc
      WHERE cc.ID = @CC_ID

      FROM CUSTOMER_BILLING_ADDRESS ba
      WHERE ba.ID = @BA_ID

      FROM CUSTOMER_SHIPPING_ADDRESS sa
      WHERE sa.ID = @SA_ID

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      If there is no relationship between the tables then that would not be possible unless you create one or you are getting only 1 record from each table, then you could use a cross join

      Never underestimate the power of human stupidity RAH

      J 1 Reply Last reply
      0
      • J jkirkerx

        I painted myself into a corner here. Was going to do a join, but realized I had nothing to join. Is it possible to get this result in 1 set?

        SELECT
        cc.ID
        , cc.CustomerID
        , cc.SessionID
        , cc.LoginID
        , cc.CardLabel
        , cc.CardBrand
        , cc.CardName
        , cc.CardNumber
        , cc.ExpMonth
        , cc.ExpYear
        , cc.CVV2
        , ba.Name1
        , ba.Name2
        , ba.CompanyName
        , ba.StreetAddress1
        , ba.StreetAddress2
        , ba.City
        , ba.StateCode
        , ba.PostalCode
        , ba.CountryCode
        , ba.Phone
        , sa.Name1
        , sa.Name2
        , sa.CompanyName
        , sa.StreetAddress1
        , sa.StreetAddress2
        , sa.City
        , sa.StateCode
        , sa.PostalCode
        , sa.CountryCode
        , sa.Phone
        FROM CUSTOMER_CARDDATA cc
        WHERE cc.ID = @CC_ID

        FROM CUSTOMER_BILLING_ADDRESS ba
        WHERE ba.ID = @BA_ID

        FROM CUSTOMER_SHIPPING_ADDRESS sa
        WHERE sa.ID = @SA_ID

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If each of the three resultsets contains exact the same columns, then you can use the UNION keyword.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        1 Reply Last reply
        0
        • M Mycroft Holmes

          If there is no relationship between the tables then that would not be possible unless you create one or you are getting only 1 record from each table, then you could use a cross join

          Never underestimate the power of human stupidity RAH

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          The only relationship is the master order table, but it can be different in 3 scenarios I'll check out the cross join. Last night I just used one of the master tables, and wrote 2 functions.

          1 Reply Last reply
          0
          • J jkirkerx

            I painted myself into a corner here. Was going to do a join, but realized I had nothing to join. Is it possible to get this result in 1 set?

            SELECT
            cc.ID
            , cc.CustomerID
            , cc.SessionID
            , cc.LoginID
            , cc.CardLabel
            , cc.CardBrand
            , cc.CardName
            , cc.CardNumber
            , cc.ExpMonth
            , cc.ExpYear
            , cc.CVV2
            , ba.Name1
            , ba.Name2
            , ba.CompanyName
            , ba.StreetAddress1
            , ba.StreetAddress2
            , ba.City
            , ba.StateCode
            , ba.PostalCode
            , ba.CountryCode
            , ba.Phone
            , sa.Name1
            , sa.Name2
            , sa.CompanyName
            , sa.StreetAddress1
            , sa.StreetAddress2
            , sa.City
            , sa.StateCode
            , sa.PostalCode
            , sa.CountryCode
            , sa.Phone
            FROM CUSTOMER_CARDDATA cc
            WHERE cc.ID = @CC_ID

            FROM CUSTOMER_BILLING_ADDRESS ba
            WHERE ba.ID = @BA_ID

            FROM CUSTOMER_SHIPPING_ADDRESS sa
            WHERE sa.ID = @SA_ID

            S Offline
            S Offline
            Sascha Lefevre
            wrote on last edited by
            #5

            If there's exactly one matching record to each other and they're in the same order you could use the ROWID to join them / to update the tables without ID with the ID from CUSTOMER_CARDDATA.

            If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

            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