2

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

SOS
  • 6,430
  • 2
  • 11
  • 29
MasterYi
  • 21
  • 2
  • use [INNER JOIN](https://learn.microsoft.com/en-us/sql/relational-databases/performance/joins?view=sql-server-ver15) – Squirrel Mar 07 '22 at 00:44

1 Answers1

2

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

Maxim
  • 854
  • 1
  • 8
  • 16