Search code examples
sqlinner-join

If the two tables are inner joined, what will be the output?


Table A: 1 1 1 2 2 3 3 3 4 4  
Table B: 1 1 2 2 3 3 5 5 5

What will be the output if the two tables are inner joined?

My answer was 1 1 2 2 3 3 but the interviewer said it wrong :/

According to my knowledge, inner join means the common factors of two tables. What should be my approach to this question?


Solution

  • Answer will be :

    1
    1
    1
    1
    1
    1
    2
    2
    2
    2
    3
    3
    3
    3
    3
    3
    

    db<>fiddle demo

    Let me explain for 1: There are three rows containing 1 in TableA and two rows with 1 in TableB, so the final output will have 3*2 = six 1. Similarly for the other values.