FAQ: Multiple Tables - Inner Joins

This community-built FAQ covers the “Inner Joins” exercise from the lesson “Multiple Tables”.

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

Web Development
Learn SQL

FAQs on the exercise Inner Joins

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!

Um hello, So each time i ‘join’ 2 tables with or without an ON statement, after compilation, i get to find out that the 2 tables will literary get glued together(as in one before the other all at once) which doesn’t seem right to me.
Could i be wrong? I would :heart: a reply.

In this exercise, I was told to combine 2 tables.
There are 2 tables in total, one is “newspaper” one is “online” if when I combine them and I use the COUNT function and I get 50 people in total. Does that mean that there are 50 people that their subscription includes newspaper and articles online?
(This is my code):

SELECT COUNT(*) 
FROM newspaper 
JOIN online 
	ON newspaper.id = 
  online.id;
3 Likes

Yes, it only joins the rows that have identical value in the id column, which means that the people in the result are the people that use online and printed subscription.

I also looked at all three tables and compared them to see this better, using this code:

SELECT *
FROM newspaper
JOIN online
ON newspaper.id= online.id
ORDER BY first_name
LIMIT 10;

SELECT *
FROM newspaper
ORDER BY first_name ASC
LIMIT 10;

SELECT *
FROM online
ORDER BY first_name ASC
LIMIT 10;

2 Likes

I ran the #3 task in this module and I keep getting this in red:

Did you remember to count all rows of online joined with newspaper?
not too sure what is going on.

I deleted it and copied the “hint” and reran and same results.
please let me know what to do…

1 Like

the results are showing the results 50
so not too sure what I am missing to “next”

1 Like

I figured it out I left a couple queries on and it seem to confuse it.

1 Like

Hey Codeacademy team,

When you guys ask us to answer questions about tables, please give us the entire context of the table so we can reference it. It’s incredible frustrating to not even know what the table layouts are when being presented new data. GIVE US THE TABLE TO REFERENCE SOMEWHERE. Thanks!

6 Likes

try use the following it should work( next user/coming users)

select count(*) from newspaper;

select count(*) from online;

SELECT count (*)

FROM newspaper JOIN online

ON newspaper.id = online.id;

1 Like

It could be me but the instructions are a bit confusing. The first lesson does not specify whether or not we are dealing with multiples tables nor do we have any reference. Please add the table or provide the schema as reference. Thank you.

3 Likes

Can’t get the first task to pass, even with copy / pasting the solution from the hint.

My code:

SELECT COUNT(*) FROM newspaper;

This lesson currently reads:

Suppose we are working for The Codecademy Times, a newspaper with two types of subscriptions:

print newspaper
online articles

Some users subscribe to just the newspaper, some subscribe to just the online edition, and some subscribe to both.

There is a newspaper table that contains information about the newspaper subscribers.

Count the number of subscribers who get a print newspaper using COUNT().

It should instead read :

Suppose we are working for The Codecademy Times, a newspaper with two types of subscriptions:

print newspaper
online articles

Some users subscribe to just the newspaper, some subscribe to just the online edition, and some subscribe to both.

There is a newspaper table that contains information about the print newspaper subscribers.

Count the number of subscribers who get a print newspaper using COUNT().

1 Like

I think one can infer that they mean the print newspaper table here.

That said, if this is a course suggestion, as this is (copyediting issue in this case), then you can submit a correction here.

I’m a little confused on this lesson because it in checkpoint 3 it reads, “Don’t remove your previous queries.
Join newspaper table and online table on their id columns (the unique ID of the subscriber).
How many rows are in this table?” and the goes on to provide a hint with code that has not been introduced to us as beginners nor does it state anywhere in the checkpoint that these are the steps you need to take. It reads, "Suppose we do:

SELECT *
FROM newspaper
LIMIT 10; 

SELECT *
FROM online
LIMIT 10;

Where in the previous lessons does it say these are the steps needed to follow. When am I supposed to do this first, before joining tables? Is this always how I should code it? Is it only in certain cases? What kind of cases? Is there a definitive, concrete, set-in-stone way of doing coding it? I understand the syntax, but sometimes the syntax changes depending on the query. So, how do I know when I need to use this method?

1 Like

can someone help me with inner join?

What is your question?
Unless you’re referring to this(?):

SELECT COUNT (*)
FROM newspaper
JOIN online
ON newspaper.id = online.id;

if you have code, please post it.

You have the answer right in front of you:
E.g. Run
SELECT * FROM newspaper;

In this example, I am wondering why does
SELECT COUNT(*)
FROM newspaper
JOIN online
ON newspaper.id = online.id;

work, but not
SELECT COUNT(*)
FROM newspaper
JOIN online
USING (newspaper.id);
In the previous lesson, using the the USING command worked. thank you

in regards to the previous lesson, its lesson 3
SELECT *
FROM subscriptions
JOIN orders
USING(subscription_id);

I have a similar doubt. I expected the two tables to be glued together like that, but I expected only one of the ‘id’ columns to remain, since these are the columns used in the ON statement, and from the animation in the lesson it would seem that only one of those columns should remain after joining them.