Skip to content
Advertisement

avoid duplication when joining tables without unique id using foreign keys

I’m facing this issue where I don’t really know how to handle duplicate rows when joining two tables.

I have two tables I’d like to join

Value_x table :

Value_y table:

Because of the Campaign column, ID are not unique in each table and for example, left join table output looks like this:

Ideally I’d like to have the following output

How would you handle a situation like this? I read something about foreign keys… I’m not familiar with this concept how can it help in this context? Or is there a way to perform a join at the campaign level?

Advertisement

Answer

Below is for BigQuery Standard SQL

You can test, play with above using sample data from your questions as in below example

with result

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