I'm new to SQL, and i got this piece of code, inspired by this post Delete duplicate rows from a BigQuery table
I ran the code, and understood that it deduplicates my table, but i'm not sure how.
The code is the one that follows
WITH product_query AS(
SELECT
DISTINCT
v2ProductName,
productSKU
FROM `data-to-insights.ecommerce.all_sessions_raw`
WHERE v2ProductName IS NOT NULL
)
SELECT k.* FROM (
#aggregate the products into an array and only take 1 result
SELECT ARRAY_AGG (x LIMIT 1)[OFFSET(0)] k
FROM product_query x
GROUP BY productSKU
)
I think i got the first part, but, starting from "SELECT k.*"... i'm not sure what am i looking at. What the "k" and the "x" are supposed to mean? And what is the OFFSET function?