Skip to content
Advertisement

SQL how to select a single value from a table with LEFT JOIN, In Google Datastudio

I have two tables one table called mailing_events and one table called mailing_outletcontact. Examples of my tables are below.

The mailing table is very simple with no duplicates:

My Second table “mailing_outletcontact” has duplicates in the email field.

I am trying to query the database in Datastudio with my goal being to get the “outletcontact_id” field with my first table data.

I tried to do a left join, however, since there are multiple values in the second table I had to pick a row to match. To me it doesn’t matter which row it matches, I decided to pick the one with the highest id field.

My code is:

This didn’t work, does anyone know where I went wrong. Or how to fix my issue altogether. which is to get the “outletcontact_id” field with my first table data.

EDIT: I am running the SQL in Datastudio so the error message isn’t great. The error ID also doesn’t provide any value after looking online. The error message is:

Second EDIT: The Answer provided by shawnt00 does work in SQL client software such as DBeaver. So if you are reading this with a similar issue that should help.

It still does not work in Datastudio with their SQL connection, so they might use a different standard or something?

Advertisement

Answer

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement