Number of lines increases after use of JOIN

Asked

Viewed 346 times

2

Hello, I’m new to SQL and I’m having a doubt. As in the example below, I wanted to take from a table 'b' the description of the code present in table 'a'. But the number of rows in table 'a' when I do this increases significantly.

select a.banana, a.caju, b.descgenero 
from vegetais b
INNER JOIN desc b
on (a.cod = b.cod and a.est = b.est and a.colheita = b.colheita)

I have seen cases using INNER JOIN where table 'a' is smaller, if it does not have the corresponding code in table 'b', but I do not understand why the number of rows in table 'a' may have increased. If anyone can help me, I’d be grateful.

  • 7

    It would be nice for a [mcve] in a SQL Fiddle or thing of the kind to clarify better, and facilitate the visualization of the phenomenon..

1 answer

0

Your question is not very clear, but I believe it can only be because you have a 1-N (ONE TO MANY) relationship between your tables vegetable or desc.

For example.

Suppose your table vegetable has the cod = 1 est = 1 colheita = 1 and your table desc have the same cod = 1 est = 1 colheita = 1 but twice and not once only when you do the select below it will return two rows one for each relationship.

select a.banana, a.caju, b.descgenero 
from vegetais a
INNER JOIN desc b
on (a.cod = b.cod and a.est = b.est and a.colheita = b.colheita)

Browser other questions tagged

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