简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM