Difference between connecting tables with WHERE and with INNER JOIN

Asked

Viewed 197 times

2

I was learning SQL and came across the following instructions:

SELECT 
    tbl_Livros.Nome_Livro, tbl_Livros.ISBN_Livro, tbl_Autores.Nome_Autor
FROM 
    tbl_Livros, tbl_Autores
WHERE 
    tbl_Livros.AutorID_Livro = tbl_Autores.ID_Autor;

And the other:

SELECT 
    tbl_Livros.Nome_Livro, tbl_Livros.ISBN_Livro, tbl_Autores.Nome_Autor
FROM 
    tbl_Livros
INNER JOIN tbl_Autores ON tbl_Livros.AutorID_Livro = tbl_Autores.ID_Autor;

The 2 commands returned me the same records, I wonder what difference between them. The difference between INNER JOIN and OUTER JOIN I know, but the difference between INNER JOIN and link using WHERE I don’t know.

Thank you.

  • Where is to filter the query and innerjoin serves to connect keys in 2 or more tables. Oinnerjoin tras para vc a query in two tables being linked by a key Primary or a key Foreign

  • 1

    If the query optimizer is doing the right job, there should be no difference between these queries. They are only two ways to specify the same desired result.

1 answer

1

Here’s a visual example of my comet:

Assuming we have two tables with a ratio of 1 to 1 inserir a descrição da imagem aqui

Note the filter behavior of WHERE in the two consultations and in the 2nd Consultation observe the INNER JOIN

inserir a descrição da imagem aqui

Summarizing the INNER JOIN - Returns row when there is at least one match in both tables.

  • Resumindo o INNER JOIN - Retorna linha quando houver pelo menos uma correspondência em ambas as tabelas. and the where also. As I said: If the query optimizer is doing the right job, there should be no difference between these queries. They are only two ways to specify the same desired result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.