Implementing Joins (SQL for Data Analysis)

Hi there,

I hope you’re doing good!

I’m taking the SQL for Data Analysis course and I’m having trouble with the Joins Implementing parts. I can not make the Task1. Indeed, the query timed out…

My answer may be wrong (notice that I added the column email_id from the table emails so I’d be able to sort the table as asked) but I don’t know why. Here is my code below:

 select c.customer_id, e.email_id
 , c.first_name, c.last_name, e.email_subject, e.opened, e.clicked
 from customers c inner join emails e on c.customer_id = e.customer_id
 order by 1, 2;

Also, I’m wondering if there is not too much information to show that would be explain the result. My laptop may be not good enough for making this request. I tried to make it on another laptop more performing, but the result is the same…

Please, could anyone give me a clue ? :slight_smile:

Thanks a lot!

Have a good one guys!

Cheers,
Jacques

Hey Jacques!

Your code is very close! You can still order by a column that is not included in your select statement. I.e. instead of order by 1, 2, you can use order by 1, e.email_id and remove e.email_id from the select:

select c.customer_id,
       c.first_name,
       c.last_name,
       e.email_subject,
       e.opened,
       e.clicked
from customers c inner join emails e on c.customer_id = e.customer_id
order by 1, e.email_id;

As for the query timing out, I will have to look further into it. I will get back to you as soon as possible!

Best,
Lorraine

Hey Jacques,

We have changed to task to limit the number of rows returned. If you reload, you will see that the task now requires you to limit your results to the first 1000 (by using limit 1000). This will prevent the query from timing out.

Let me know if you have questions!

Best,
Lorraine

Hey Lorraire,

I hope you’re doing good!

Thanks for your replies!
I didn’t know that I can sort a query by a column that is not included in the select statement. It is good to know, thanks!! :slight_smile:

Thanks also for restricting the results to the first 1000, it is working now :slight_smile:

Best,
Jacques

1 Like