Skip to content
Advertisement

Find common values in many tables

I have 5 tables and I want to find the common values between them in one column. The column name differs in two tables(account_number, account,account_id).

I tried the above with the idea of every time compare the last result of the inner join with the new one but it seems wrong.

Advertisement

Answer

Your method is okay, but it can return duplicates. Another method is to use union all:

Note that this can be easily tweaked to get accounts that are in three or four tables rather than in all of them.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement