FAQ: What Are Database Keys? - Foreign Key Part 2

This community-built FAQ covers the “Foreign Key Part 2” exercise from the lesson “What Are Database Keys?”.

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

Design Databases With PostgreSQL

FAQs on the exercise Foreign Key Part 2

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!
You can also find further discussion and get answers to your questions over in Language Help.

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

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

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!

I think the query explained in this exercise is the same as inner join, and I saw this way for the first time:

SELECT person.name AS name, email.email AS email
FROM person, email
WHERE person.id = email.person_id;

Is this exactly the same as using JOIN clause:

SELECT person.name AS name, email.email AS email
FROM person
JOIN email
  ON person.id = email.person_id;

or is there any difference?

I had a chance to learn a little more about this in another topic:

Both can get basically the same result, but it depends on RDBMS. It seems that the former (implicit) way is old syntax. Now the explicit way (with JOIN clause) seems to be recommended for several reasons, such as code readability.

Hello @object2161442840,

:+1: Yes, you are correct they are the same. It’s great you found more info on the topic. I think it’s debatable on whether EXPLICIT joins are more readable :slightly_smiling_face:. I personally find implicit joins more concise and readable but don’t have issues working with either methods. It’s best to follow the development standards established by the environment you are working with.

2 Likes

In the exercise 6/7 in this chapter, I tried to use an implicit join (like this)

SELECT book.title as book, chapter.title as chapters
FROM book, chapter
ON book.isbn = chapter.book_isbn;

but the solution marked that only an explicit join would work (like this)

SELECT book.title as book, chapter.title as chapters
FROM book
JOIN chapter
ON book.isbn = chapter.book_isbn;

Why? Wouldn’t both options work, according to the theory? Is this a bug in the solution checker?
I believe both should work, but only the second option was allowed to be correct.

Foreign Key Part 2

6/7

hey there it is kinda annoying that only very verbose and solutions are accepted which are not used as such in the wild.

following should be accepted as well:

select b.title as book, c.title as chapter
  from book as b
  join chapter as c
  on b.isbn = c.book_isbn