Dipanjan Mallick
Dipanjan Mallick

Reputation: 1739

Find min(records) and max(records)

I have two tables as t1 and t2. t1 has M records, t2 has N records. Both of these two tables doesn't contain any duplicate value. If I join both of these tables then, what would be the min(records) and max(records) in terms of M and N ?

**I was asked about this question few days back during an interview and I couldn't answer this. Please help!

Thanks.

Upvotes: 1

Views: 56

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271131

The minimum records is 0 because whatever join conditions you use might always evaluate to true.

Assuming you are matching on "unique" ids (which I think is what you are trying to say by pointing out no duplicates), the maximum records is n + m, because you might use a full join between the tables, with no matching rows.

For an inner join, the maximum is least(n, m). All the rows in one table might match rows in the other -- but the non-matched rows won't be counted.

Upvotes: 1

Related Questions