When to use SQL Table Alias

Posted by Rossini on Stack Overflow See other posts from Stack Overflow or by Rossini
Published on 2008-10-13T16:35:44Z Indexed on 2010/06/16 23:42 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

I curious to know how people are using table alias. The other developers where I work always use table alias, and always use the alias of a, b, c, ect. Here's an example

SELECT a.TripNum, b.SegmentNum, b.StopNum, b.ArrivalTime
FROM Trip a, Segment b
WHERE a.TripNum = b.TripNum

I disagree with them, and think table alias should be use more sparingly. I think it should be used when including the same table twice in a query, or when the table name is very long and using a shorter name in the query will make the query easier to read. I also think the alias should be a good name instead of a letter. In the above example if I felt I needed to use 1 letter table alias I would use t for the Trip table and s for the segment table.

© Stack Overflow or respective owner

Related posts about sql

Related posts about database