Skip to content
Advertisement

BIGQUERY: Replace a ‘null’ result from one table with a user id from another table

trusty BQ experts.

Background: I have users reading articles on a website (User Table A) and users clicking through to articles from an email (User Table B) and have BQ view tables for each user set. User Table A is missing some user_id of the users who have clicked through from the emails. See User Table A below.

  • I’m want to create a single view/table which replaces a null user_id result in User Table A with the user_id from User Table B IF the viewed_at and clicked_at are the same AND the article_id from User Table A and User Table B are also the same.

  • I also want to retain the user_id null result if the corresponding viewed_at/clicked_at and article_id are not found in User Table B.

I hope this makes sense.

Please help. This has been doing my head in for months.

Advertisement

Answer

Below is for BigQuery Standard SQL

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