Introducere în BigQuery
Matthew Forrest
Field CTO
INNER JOIN: Valorile există în ambele tabele.
LEFT JOIN: Toate rândurile din tabelul stâng, potrivire cu tabelul drept.
RIGHT JOIN: Toate rândurile din tabelul drept, potrivire cu tabelul stâng.
FULL JOIN: Toate rândurile din ambele tabele, potriviri și nepotriviri.
CROSS JOIN: Fiecare rând asociat cu fiecare rând din ambele tabele.

Customers: tabel stâng
Orders: tabel drept
INNER JOIN: Clienți și comenzile lor corespunzătoare
LEFT JOIN: Toți clienții, chiar dacă nu au plasat comenzi
RIGHT JOIN: Toate comenzile, chiar dacă ID-ul clientului lipsește
FULL JOIN: Toți clienții și toate comenzile, chiar fără interacțiuni
CROSS JOIN: Fiecare comandă asociată cu fiecare client, fără condiții
SELECT
c.customer_id, s.product_name
FROM customers c
-- The INNER keyword is optional
JOIN sales_data s
ON c.customer_id = s.customer_id;
| customer_id | product_name |
|-------------|----------------------|
| 1 | Bluetooth Headphones |
| 2 | Running Shoes |
SELECT
c.customer_id, s.product_name
FROM customers c
LEFT JOIN sales_data s
ON c.customer_id = s.customer_id;
| customer_id | product_name |
|-------------|----------------------|
| 1 | Bluetooth Headphones |
| 2 | Running Shoes |
| 3 | null |
SELECT
c.customer_id, s.product_name
FROM customers c
RIGHT JOIN sales_data s
ON c.customer_id = s.customer_id;
| customer_id | product_name |
|-------------|----------------------|
| 1 | Bluetooth Headphones |
| 2 | Running Shoes |
| null | External Microphone |
SELECT
c.customer_id, s.product_name
FROM customers c
OUTER JOIN sales_data s
ON c.customer_id = s.customer_id;
| customer_id | product_name |
|-------------|----------------------|
| 1 | Bluetooth Headphones |
| 2 | Running Shoes |
| 3 | null |
| null | External Microphone |
SELECT
c.customer_id,
s.product_name,
-- Adding table names separated
-- by a comma is a CROSS JOIN
-- Order is determined by the
-- left table, here "customers"
FROM customers c, sales_data s;
| customer_id | product_name |
|-------------|----------------------|
| 1 | Bluetooth Headphones |
| 1 | null |
| 2 | Bluetooth Headphones |
| 2 | null |
| 3 | null |
| 3 | Bluetooth Headphones |
SELECT
c.customer_id,
payments.method
FROM customers c,
UNNEST(
customers.payment_methods
) payments;
| customer_id | product_name |
|-------------|--------------|
| 1 | Visa |
| 1 | Mastercard |
| 1 | Venmo |
| 1 | Paypal |
| 2 | Amex |
| 2 | Visa |
Introducere în BigQuery