0

I know I can do:

SELECT COUNT(*) FROM table_a INNER JOIN table_b ON (table_a.attribute = table_b.attribute)

To do an inner join based on the same attributes in table_a and table_b.

But what if I have over 100 attributes and I want to do an inner join only when all the attributes are the same. Is there an easier way than to list on all 100+?

Liondancer
  • 15,721
  • 51
  • 149
  • 255

2 Answers2

1

What about this?

SELECT COUNT(*) FROM table_a INNER JOIN table_b ON 
(table_a.attribute1 = table_b.attribute1 and 
table_a.attribute2 = table_b.attribute2 and 
table_a.attribute3 = table_b.attribute3 ... and
table_a.attribute100 = table_b.attribute100)

Use Aginity+Excel to create the join faster :)

karim_op
  • 11
  • 2
0

If the attributes are the same you can use NATURAL JOIN. It's not one I've actually used but it should do exactly What you want. E.g http://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqljnaturaljoin.html.

  • 1
    Natural join can be used in ad hoc queries, but never in programming. (If a column name changes, applications quit to work as expected...) – jarlh Mar 06 '15 at 09:06