Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Basic SQL Link Table

Hi, 

Im a beginner at SQL and I'm having difficulty just making a basic link table from 2 separate tables. My code is as follows:

ODBC CONNECT TO xxx.xxxx.xxx;


LOAD date1,
     id;
SQL SELECT *
FROM gbakes1;

LOAD  id,
date2;
SQL SELECT *
FROM gbakes2;

This loads 2 tables linked by the unique key (id) I'd like them to be concatenated into one table. I'm not sure if I can use the correct terminology to describe this but basically there are as many id fields as date1 fields but not as many date2 fields as id fields, so if the missing date2 fields could just be put in as null that would be great.

Thanks so much in advance! Im sure the solution is really simple but whenever I try look something up the explanations and examples are really complex

George

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

You can use the CONCATENATE keyword to append all rows from the second table to the first table, regardless whether the fields in table 2 also exist in table 1, and if they don't they will have a null value:

Table1:

LOAD date1 as DateField,

id as ID,

'Table1' as Source;

SQL SELECT *

FROM gbakes1;

CONCATENATE (Table1) LOAD id as ID,

date2 AS DateField,

'Table2' as Source;

SQL SELECT *

FROM gbakes2;

Field "Source" would help you with set analysis or conditions in charts to select from which table do you actually want to select.

View solution in original post

6 Replies
Anil_Babu_Samineni

You can use like to get single table in DM.

LOAD date1 as DateField,

    id as ID;

SQL SELECT *

FROM gbakes1;

LOAD  id as ID,

date2 as DateField;

SQL SELECT *

FROM gbakes2;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Miguel_Angel_Baeyens

You can use the CONCATENATE keyword to append all rows from the second table to the first table, regardless whether the fields in table 2 also exist in table 1, and if they don't they will have a null value:

Table1:

LOAD date1 as DateField,

id as ID,

'Table1' as Source;

SQL SELECT *

FROM gbakes1;

CONCATENATE (Table1) LOAD id as ID,

date2 AS DateField,

'Table2' as Source;

SQL SELECT *

FROM gbakes2;

Field "Source" would help you with set analysis or conditions in charts to select from which table do you actually want to select.

Anonymous
Not applicable
Author

Hi Miguel and Anil,

Thank you both for your answers, I tested and used the 2 methods and actually I found each one useful for different things.

Thanks again!!

Anil_Babu_Samineni

Does it mean, You got answer

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

Yes, I tried to select both for correct answer, but after I clicked one there was no longer the option for another.

dathathreya
Creator

Might it would help.