Andrew McComb
Andrew McComb

Reputation: 47

Why is it necessary to join on multiple columns SQL?

In a general sense in SQL joins, what is the benefit to joining tables with multiple versus one column?

Upvotes: 1

Views: 1171

Answers (1)

Tyler Lee
Tyler Lee

Reputation: 2785

It depends on the structure of your data. One column may not be enough to properly identify matching rows.

Consider joining on Address data (as an example). If you only join on the Address line, but not City/State, you might have rows match to both

123 Front St, New York City, NY  

and

123 Front St, Los Angeles, CA  

even though your person only lives in one place.

side note: joining on address lines probably means your database needs normalizing. I use it as an example only

Upvotes: 5

Related Questions