Difference between INNER JOIN, JOIN and WHERE?

Asked

Viewed 1,113 times

1

I need to perform a query that return me information according to a certain condition, I have always used the Where for not knowing if he could use another method. So what’s the difference between Where, Inner Join and Join. I can use when every one of them?

If you can give examples. Thank you.

  • 1

    Best way to understand: https://i.stack.Imgur.com/1UKp7.png

  • Best link to understand this https://answall.com/questions/6441/qual-%C3%A9-a-difference%C3%A7a-entre-Inner-Join-e-outer-Join

1 answer

4


Cara has a lot of material on this, but this image I sent as a comment will help you better.

Basically you have to understand the concept of left and right (left e right), for example:

Your table in FROM it is your table esquerda, that is to say, left, when doing a JOIN.

FROM tabela1 X
LEFT OUTER JOIN tabela2 Y ON Y.campo1 = X.campo2

I mean, you’re bringing everything from table X, plus the Y records that link to X.

Now in:

FROM tabela1 X
RIGHT OUTER JOIN tabela2 Y ON Y.campo1 = X.campo2

You bring everything that’s on your table direita "Y" plus "X" that has to do with "Y".

INNER only what is common in the 2 tables, and FULL brings EVERYTHING regardless of relationships.

Browser other questions tagged

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