How to join two tables with same ID?

Viewed 664

For example, I have two tables.

Table1:

Schools Type City
school1 A CityA
school2 B CityB

Table2:

schools population time
school1 1000 01/01/2021
school2 2000 01/02/2021
school3 3000 01/03/2021

I want to figure out how to join them like below (without school3):

schools type city population time
school1 A CityA 1000 01/01/2021
school2 B CityB 2000 01/02/2021

I am a beginner and really confused about how to deal with this problem.

http://sqlfiddle.com/#!18/3eaf9/2

1 Answers

You should use JOIN:

SELECT t1.schools, t1.type, t1.city, t2.population, t2.time
FROM
  Table1 t1
INNER JOIN
  Table2 t2 ON t1.schools = t2.schools

More information how JOIN works you can see in picture in this post

Difference between INNER JOIN and OUTER JOIN see here

Related