Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Columns with the same name

Back to Forum: Tech Off
  • User profile image
    W3bbo

    'lo

    When performing SQL JOIN queries, I noticed it doesn't prepend the column names with the table name.

    So question: How do you refer to a column by name when there are two columns with the same name in a returned query?

  • User profile image
    GeSpot

    I don't think you can get the data by using the column names.  You can use the column index, or better yet, alias your query results to return different names for the columns..

  • User profile image
    W3bbo

    GeSpot wrote:

    I don't think you can get the data by using the column names.  You can use the column index, or better yet, alias your query results to return different names for the columns..



    Yep, thanks... solved it with Aliases.

  • User profile image
    bitmask

    I typically alias the columns to avoid that sort of situation, I don't think there is a way on the client side to get to the second occurrence without using an ordinal number.

    I.e:

    SELECT 
      V.VisitID,
      AdmDate.DateID AS AdmDateID,
      DisDate.DateID AS DisDateID

    FROM Visits V 
       LEFT JOIN Dates AdmDates ON V.AdmDateID = AdmDates.DateID
       LEFT JOIN Dates DisDates ON V.DisDateID = DisDates.DateID

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.