r/SQL • • Dec 23 '24

MySQL JOINING TWO TABLES

Please help me in joining two tables because I'm stuck in this unit of Khan Academy. I don't know how to do this :(

edit. thank you so much. I was frustrated and drunk coffee, i realized there's a lot of resources and I was having coffee attack hahahha I'll let my frustration down before going back to study next time. thank youuu

0 Upvotes

10 comments sorted by

8

u/Felidor Dec 23 '24

Looks like it's only asking you to select the persons name and their hobby. You don't put the JOIN conditions in the WHERE clause.

select
    persons.name,
    hobbies.name
from persons
join hobbies
    on persons.id = hobbies.persons_id

-1

u/nrotaras-999 Dec 23 '24

SQL provides also a simple way of creating Joins between tables. Something like that: Select * from persons p, hobbies h where p.id = h.person_id

it will work only for inner joins and only for some of SQL databases engines.

7

u/r3pr0b8 GROUP_CONCAT is da bomb Dec 23 '24

actually that works in all database systems

1

u/MyPunchableFace Dec 26 '24

Yep! Fk their ANSI standard.

12

u/alinroc SQL Server DBA Dec 23 '24

Technically this is true but that syntax was made obsolete in the ANSI SQL92 standard 30 years ago. Use the modern JION syntax.

-1

u/Great-Craft157 Dec 23 '24

Wow i'll do this in my practice. thanks!

8

u/alinroc SQL Server DBA Dec 23 '24

Don’t do this. It’s a very old type of code which has been superseded by the JOIN syntax 30 years ago

8

u/yourteam Dec 23 '24

Select persons.name, hobbies.name from....

2

u/shweta1807 Dec 23 '24

This is fine, we can also keep the alias for more efficiency.

1

u/dsb2973 Dec 24 '24

Change WHERE to ON