Number of rows increases after use of JOIN

2

Hello, I'm new to SQL and am having a question. As in the example below, I wanted to get a description of the code in the 'a' table from a table 'b'. 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' gets smaller, if I do 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'll be grateful.

    
asked by anonymous 11.08.2016 / 00:30

1 answer

0

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

For example.

Suppose your vegetable table has cod = 1 est = 1 colheita = 1 and your desc table has the same cod = 1 est = 1 colheita = 1 but twice and not one when you 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)
    
11.08.2016 / 03:20