Skip to content
Advertisement

How To Extract Distinct ID’s Present In One Table But Not Another

I have two tables, one with the sales entries (multiple of the same salesman id number), and another that is a master file of sales people (only one salesman id per each salesman).

How can I write a query (via BigQuery) which identifies the distinct salesman_ids which are present in the sales_table, but are NOT present in the salesman_ids table?

Thanks!

Advertisement

Answer

Below option is for BigQuery Standard SQL

#standardSQL
SELECT DISTINCT e.salesman_id
FROM sales_entries e
LEFT JOIN sales_people p
USING(salesman_id)
WHERE p.salesman_id IS NULL
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement