Differences between Natural Join and Inner Join

Asked

Viewed 10,002 times

12

What characteristics differentiate a consultation performed with the use of Natural Join other with the use of Inner Join? Is there any question related to performance or any other condition that leads me to choose one over the other?

For the example below, we would have the following queries:

select livro.nome_livro, editora.nome_editora from livro natural join editora

or

select livro.nome_livro, editora.nome_editora from livro
inner join editora on editora.codigo_editora = livro.codigo_editora

inserir a descrição da imagem aqui

1 answer

15


The NATURAL JOIN He’s just a facilitator. It is not faster or does nothing better, it only allows a shorter syntax if the junction is simple, your example illustrates this well. Both do exactly the same thing in the same way but the first is easier to write.

The name is so because this is the most natural way to make a INNER JOIN simple.

As you can see it is not possible to produce results with more complex expressions using natural form.

If the * is used to pick up the fields in tables with NATURAL JOIN columns of the same name will not be shown repeated in the result.

Wikipedia article.

  • My question is, if this method impacts performance?

  • Like I said in the first line, no. Of course if you buy with comparable things, compare one form with another that does something else of course there is a difference, but then the problem is not knowing how to compare.

Browser other questions tagged

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