
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
.png)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
.png)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does it mean, You got answer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I tried to select both for correct answer, but after I clicked one there was no longer the option for another.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Might it would help.
