-2

I am just starting to learn SQL. Can someone explain what ON means in the example?

SELECT title, imdb_score
FROM films
JOIN reviews
ON films.id = reviews.film_id
WHERE title = 'To Kill a Mockingbird';
reshomesho
  • 1
  • 1
  • 1

4 Answers4

2

ON films.id = reviews.film_id

To specify JOIN condition. With ON clause you specify exactly on which column you want to match both table records. You can as well specify extra conditions like

ON films.id = reviews.film_id
AND <more condition>
Rahul
  • 76,197
  • 13
  • 71
  • 125
0

It's a join condition. In your example you will get title and imdb_score from those rows from films and reviews, which have the same id and film_id.

https://www.geeksforgeeks.org/sql-on-clause/

RedMurloc
  • 115
  • 1
  • 11
0

'ON' shows the connection between tables. For your example, the main table is 'films' and you want to bring data from table 'reviews'. If you dont tell computer how to connect data it cant know which movie has which reviews. You are saying that id's are the same for both of this table when you use 'ON'

emrearan
  • 3
  • 3
0

I would add for better readability, the ON right next to the table name you want to join

SELECT title, imdb_score
FROM films
JOIN reviews ON films.id = reviews.film_id
WHERE title = 'To Kill a Mockingbird';
Wevaya
  • 11
  • 1