For step 3.2 of 10 (using JOIN to write a second query looking just for ‘Fashion Magazine’), is there a difference in performance between:
SELECT *
FROM orders
JOIN subscriptions
ON orders.subscription_id = subscriptions.subscription_id
AND subscriptions.description = 'Fashion Magazine';
and the answer in the Hint:
SELECT *
FROM orders
JOIN subscriptions
ON orders.subscription_id = subscriptions.subscription_id
WHERE subscriptions.description = 'Fashion Magazine';
I don’t know what i’m doing wrong…
Could someone help me?
Here is my code:
SELECT *
FROM orders
JOIN subscriptions
ON orders.subscription_id = subscriptions.subscription_id
WHERE subscriptions.description = ‘Fashion Magazine’;
It took a little while to figure this one out. I think your query is correct but the code editor wants both queries to be in the editor at the same time like this:
This is misleading and not a practical step in my opinion. I don’t know why you would realistically keep the first section, and then repeat it below with an added WHERE clause.
After rereading the instructions it does say to “add a second query”, but within the flow of creating queries, I interpreted that as “keep the query you wrote, and now add a WHERE clause”.
I tested it, and you’re correct. You need both queries in the Codecademy environment for step 2 to work. This is probably designed to get us to type it all out again for additional practice.
When we do this and we join tables using the customer_id for example, are we actually matching up the customer ids even if they aren’t int he same order? Its not just equating the first row in one table with the first row in another table?
I feel like it must be matching but just want to check that is correct?
I think the verbage was a little confusing. I understood it wanted a second query. But it could also say, created a second query with another table. Basically, stacking the table instead of just joining the tables column to column.
On exercise 3/10, I’m noticing that the subscription_id column is duplicated. What is causing this? Is there a way to avoid it when joining tables? Thanks!
I have the same question. It seems to me that the default hierarchy between tables follows FROM to JOIN, in other words, whatever you’re selecting from table FROM will be combined to table JOIN, so now JOIN is the reference table for the previous two separate tables.
In 3/10 on step 2 - Add a second query after your first one that only selects rows from the join where description is equal to ‘Fashion Magazine’.
I wanted to try to see if I cold only select rows that were ‘Fashion Magazine’ and ‘Sports Magazine’ (for example) and was not sure how to do this.
My original lines of code were correct and these were:
SELECT *
FROM orders
JOIN subscriptions
ON orders.subscription_id = subscriptions.subscription_id
WHERE subscriptions.description = ‘Fashion Magazine’
;
I played around with what I could add so that it selected rows from more than just ‘Fashion Magazine’ using AND and OR but was not getting any results. How would I go about specifying that I want to join the results from two different rows and not just one while using a WHERE command?