Search code examples
sqlgoogle-app-maker

Joining two large tables using a calculated model in AppMaker


I have two SQL datasources in Google AppMaker. Both will have tens of thousands of records in them:

LastLogins:

+-------------------+-----------+
|       Email       | LastLogin |
+-------------------+-----------+
| email@domain.com  | 1/1/2019  |
| email2@domain.com | 12/1/2018 |
+-------------------+-----------+

and Licenses:

+------------------+---------+------------+
|      Email       |  SkuID  |  SkuName   |
+------------------+---------+------------+
| email@domain.com | 1001001 | Enterprise |
| email2@domain.com| 1001001 | Basic      |
+------------------+---------+------------+

I'd like to join the tables to create a calculated datasource with this data:

+------------------+---------+------------+-----------+
|      Email       |  SkuID  |  SkuName   | LastLogin |
+------------------+---------+------------+-----------+
| email@email.com  | 1001001 | Enterprise | 1/1/2019  |
| email2@email.com | 1001001 | Basic      | 12/1/2018 |
+------------------+---------+------------+-----------+

I tried a few different join commands but none worked. This is my current iteration:

select 
    m.Email,
    m.SkuID,
    m.SkuName,
    l.Email,
    l.LastLogin
from Licenses m ,LastLogins l
full join LastLogins on Licenses.Email = LastLogins.Email

The error I get is;

Exception: Malformed SQL. More information: Error with SQL statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'full join LastLogins on Licenses.Email = LastLogins.Email LIMIT 26' at line 3.


Solution

  • You are almost there, but your syntax to JOIN tables is wrong.

    The syntax is :

    FROM <table1> as <alias1>
    INNER JOIN <table2> as <alias2> ON ...
    

    Try :

    select 
        m.Email,
        m.SkuID,
        m.SkuName,
        l.LastLogin
    from Licenses as m
    inner join LastLogins as l on l.Email = m.Email