Skip to content
Advertisement

does equi join return duplicate column

Consider following points:

  1. As we know, inner join returns the duplicate column for which we have defined the joining condition.

  2. And we know natural join it removes the duplicate.

  3. I know we can use equi join:

    or

I have confusion in this third point. I want to know what is the scenario in equi join what it returns? Does it return with duplicate column where we have defined the joining condition like inner join.

Advertisement

Answer

To answer titled question: Yes, if your query uses SELECT *. While your focus is on the JOIN clause, you are forgetting fundamentals about the SELECT clause in SQL.

By the way your #3 (your definition of equi join) is equivalent to #1 (inner join). In #3, the former using WHERE is the older, de-emphasized (ANSI-89) implicit join style and the latter using JOIN is the current, standard (ANSI-92) explicit join. Both return same results and should render same performance but readability arguably differs. See Explicit vs implicit SQL joins.

The reason you receive duplicate columns for these equi-join cases is the SELECT clause requests for all columns of all joined tables since you do not qualify the asterisk,*:

However, using asterisk alone is an abbreviated, convenience method but the recommended way is to explicitly control your resultset by selecting specific columns. This is crucial for application builds where column order and existence is required and helps in code readability and maintainability. See Why is SELECT * considered harmful?

Below are examples that can be used to avoid duplicate columns: qualifying the asterisks, subsetting/omiting columns, and even renaming/re-ordering columns with aliases .

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