2 Replies Latest reply on Oct 19, 2012 2:16 AM by Matt Morgenroth

    Concatenation of two tables

    Philip George

      Hi,

       

      I have two tables.

       

      Table A

      ----------

       

      Name    Address    Salary     Job

      Ram      ABC          1000      Designer

      Sam      EFG          2000      Architect

       

      Table B

      ----------

      Name    Address    Previous Salary        Previous Job

      Ram      ABC            100                      engineer

      Sam      EFG            200                      developer

       

      Can I do a concatenation of these tables

      Resultant table should look like

       

      Name    Address    Salary     Job           Previous Salary        Previous Job

      Ram      ABC          1000      Designer

      Sam      EFG          2000      Architect

      Ram      ABC                                           100                      engineer

      Sam      EFG                                           200                      developer

       

       

       

       

      Also I want to know what all things we should take care when we create a datamodel in Tableau.or when we make joins to multiple tables.

       

       

      Regareds,

      Philip George

        • 1. Re: Concatenation of two tables
          Mark Holtz

          Hi Philip,

           

          To directly answer your question, what kind of database is the data coming from? Could you just do a UNION in your sql statement?

           

          SELECT Name, Address, Salary, Job, NULL AS PreviousSalary, NULL AS PreviousJob
          FROM SourceTable1

          UNION ALL

          SELECT Name, Address, NULL AS Salary, NULL AS Job, PreviousSalary, PreviousJob
          FROM SourceTable2

           

          Other observations: Is there a reason you don't just join the tables on the Name and Address Fields so your resultant table looks like this?
          Name    Address    Salary     Job           Previous Salary        Previous Job
          Ram      ABC          1000      Designer       100                         engineer
          Sam      EFG          2000      Architect        200                         developer

          1 of 1 people found this helpful
          • 2. Re: Concatenation of two tables
            Matt Morgenroth

            That looks like the right answer.

            It is done using custom SQL.

            If using Excel, it can be a bit frustrating.  Here is a working example with some additional notes:

            union (Excel)

            SELECT

              NULL AS [mon_Date],

              [DNBP$].[Date] AS [Date],

              [DNBP$].[DNBP (ppb)] AS [DNBP (ppb)],

              [DNBP$].[GW Level] AS [GW Level],

              [DNBP$].[ID] AS [ID],

              [DNBP$].[link] AS [link],

              [DNBP$].[Well] AS [Well],

              NULL AS [mon_Ppt-in]

            FROM [DNBP$]

            UNION

            SELECT

              [Precip$].[mon_Date] AS [mon_Date],

              [Precip$].[mon_MMMYY] AS [Date],

              NULL as [DNBP (ppb)],

              NULL AS [GW Level],

              NULL AS [ID],

              [Precip$].[link] AS [link],

              NULL AS [Well],

              [Precip$].[mon_Ppt-in] AS [mon_Ppt-in]

            FROM [Precip$]

             

            Note!  UNION ALL is best.  Results are consistently 'union-like'

            and more than 2 tables require it to work

             

            AND! Nulls will be interpreted as '=abc' not '#', so instead of Null, use 0.

            1 of 1 people found this helpful