Hi there,
I am having an issue where if I try to view multiple query results, the 2nd table I query will not show.
I am working on the Marketing Attribution project for Cool T-shirts. If try to view the first_touch table and last_touch table at the same time only the query I enter first will show. So, if I do the following then only the first_touch table shows:
SELECT * FROM first_touch LIMIT 10; – this query shows
SELECT * FROM last_touch LIMIT 10; – this query does not show
SELECT 2; – this query shows
SELECT COUNT (DISTINCT user_id)
FROM page_visits
WHERE page_name = ‘4 - purchase’; – this query shows
If is swap the first 2 queries then still the 2nd query does not show:
SELECT * FROM last_touch LIMIT 10; – this query shows
SELECT * FROM first_touch LIMIT 10; – this query does not show
SELECT 2; – this query shows
SELECT COUNT (DISTINCT user_id)
FROM page_visits
WHERE page_name = ‘4 - purchase’; – this query shows
I added a 3rd basic query (i.e. SELECT 2;) to test if something in the syntax means that the code stopped working after the first query, I also tried the 4th query to see if something a little more complex worked… and it did.
So I am completely stumped… why doesn’t the 2nd query work?
Full disclosure of my code below:
WITH first_touch AS (
SELECT user_id,
MIN(timestamp) as first_touch_at
FROM page_visits
GROUP BY user_id),
ft_attr AS (
SELECT ft.user_id,
ft.first_touch_at,
pv.utm_source,
pv.utm_campaign
FROM first_touch ft
JOIN page_visits pv
ON ft.user_id = pv.user_id
AND ft.first_touch_at = pv.timestamp
),
last_touch AS
(SELECT user_id,
MAX(timestamp) AS last_touch
FROM page_visits
WHERE page_name = ‘4 - purchase’
GROUP BY user_id
)
SELECT * FROM first_touch LIMIT 10;
SELECT * FROM last_touch LIMIT 10;
SELECT 2;
SELECT COUNT (DISTINCT user_id)
FROM page_visits
WHERE page_name = ‘4 - purchase’;