SQL: When joining tables when to use table.column?

Discussion in 'OT Technology' started by SubOptimal, Mar 1, 2010.

  1. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    When joining tables, when should I use table.column and when should I just use column?

    Do you always include the table name like below?

    SELECT orders.time, orders.id, details.weight, details.product
    FROM orders, details
    WHERE orders.id = details.id AND details.weight > 2
    GROUP BY orders.time;
     
    Last edited: Mar 1, 2010
  2. DouggieJ

    DouggieJ OT Supporter

    Joined:
    Nov 1, 2007
    Messages:
    8,126
    Likes Received:
    0
    Location:
    New York, NY USA
    You only need to use the table name when the column is ambiguous (i.e. more than one table has a column with the same name)
     
  3. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Will do, thanks!
     

Share This Page