FAQ: First- and Last-Touch Attribution - The Attribution Query I

This community-built FAQ covers the “The Attribution Query I” exercise from the lesson “First- and Last-Touch Attribution”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise The Attribution Query I

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

This tells us the first time that each user visited our site, but does not tell us how they got to our site — the query results have no UTM parameters! We’ll see how do get those in the next exercise.

SELECT user_id, MAX(timestamp) AS ‘last_touch_at’, utm_source
FROM page_visits
GROUP BY user_id;

For this exercise, I know the activity does not ask us to find the utm source, but could we just do this by selecting the utm_source column?

I’m asking this because the next exercise goes from 10 to 200 real fast and I’ve been stuck for 2 days trying to understand the next few exercises (which are related to this) :upside_down_face::upside_down_face::upside_down_face:

1 Like

Yes, all you have to do is add the utm_source column.

It will show the correct value, filtered by your MAX(timestamp) and WHERE condition.

Can anybody tell me what is wrong with this code?


WHEN timestamp = MIN(timestamp) THEN ‘first_touch_at’

WHEN timestamp = MAX(timestamp) THEN ‘last_touch_at’


END AS ‘First AND Last touch’

FROM page_visits

WHERE user_id = 10069

I am getting this but I want all the rows with first, last and null. I am only getting last_touch row